how to export datatable to excel in datatable.js code example

Example 1: export table data to excel in jquery

$( document ).ready(function() {
	$(".export").click(function() {
		var export_type = $(this).data('export-type');		
		$('#data_table').tableExport({
			type : export_type,			
			escape : 'false',
			ignoreColumn: []
		});		
	});
});

Example 2: datatable export bar

$(document).ready(function () {
  $("#example").DataTable({
    dom: "lBfrtip",
    columnDefs: [{ orderable: false, targets: 0 }],
    select: true,
    buttons: [
      "pageLength",
      {
        extend: "excel",
        exportOptions: {
          columns: ":visible",
        },
      },
      {
        extend: "csv",
        exportOptions: {
          columns: ":visible",
        },
      },
      {
        extend: "pdf",
        exportOptions: {
          columns: ":visible",
        },
      },
      {
        extend: "print",
        text: "Print all",
        exportOptions: {
          columns: ":visible",
        },
      },
      {
        extend: "print",
        text: "Print selected",
        exportOptions: {
          columns: ":visible",
        },
      },
      "colvis",
    ],
  });
});