Not able to export data into xlsx format using jquery

Occasional Visitor


I have written below script to generate data into xlsx format.

But I am getting message as below when I am opening xlsx excel sheet to view the data

'Excel cannot open the file abc.xlsx because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file'.

function exportToExcel(){
var downloadurl;
var dataFileType = 'application/';
var tableSelect = document.getElementById('table2excel');
var tableHTMLData = tableSelect.outerHTML.replace(/ /g, '%20');
// Specify file name
filename = 'abc.xlsx';
// Create download link element
downloadurl = document.createElement("a");
var blob = new Blob(['\ufeff', tableHTMLData], {
type: dataFileType
navigator.msSaveOrOpenBlob( blob, filename);
// Create a link to the file
downloadurl.href = 'data:' + dataFileType + ', ' + tableHTMLData;
// Setting the file name = filename;
//triggering the function;



0 Replies