datatables export excel customize code example

Example: 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",
    ],
  });
});