I am trying to generate an excel file in xlsx format and here is my code
var element = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,' + encodeURIComponent(doc);
let downloadElement = document.createElement('a');
downloadElement.href = element;
downloadElement.target = '_self';
downloadElement.download = 'Data.xlsx';
document.body.appendChild(downloadElement);
downloadElement.click();
Variable doc
contains the html table as string. But when I open the file I see an error in ms excel.
Excel cannot open the file 'Data.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.
I tried downloading it in xls format using this article, it worked but still get a warning message every time I open the downloaded file.