Home » Javascript » Export Data to excel file from datatable using js or jquery

Export Data to excel file from datatable using js or jquery

Posted by: admin June 30, 2018 Leave a comment

Questions:

I am trying to export data to excel file using javascipt or jquery.
The problem is with getting the headers and duplicates records.Following are the scenarios-

1)

var otable = $('#plExcelReport').DataTable();

$('<table>').append(otable.$('tr').clone()).table2excel({
                // exclude CSS class
                exclude: ".noExl",
                name: "Worksheet Name",
                filename: xcelFileName
            });

All data from data table gets exported to excel file except headers.

2)

var otable = $('#plExcelReport').DataTable();

$('#plExcelReport').append(otable.$('tr').clone()).table2excel({
                // exclude CSS class
                exclude: ".noExl",
                name: "Worksheet Name",
                filename: xcelFileName
            });

Header appear but data from first page gets duplicated in excel file

I want to achieve both things i.e header and non-duplicate records ,please help

Answers: