I am converting html table
into excel
file. on open it throws and error as follows:
how to prevent it. what is the correct way to conversion?
here is my js code :
let downloadLink;
const dataType = "data:application/vnd.ms-excel";
const tableSelect = `<table>
<thead>
<tr>
${this.setTitle(data)}
</tr>
</thead>
<tbody>
${this.setBody(data)}
</tbody>
</table>`;
filename = filename ? filename + ".xls" : "excel_data.xls";
downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
var tableHTML = tableSelect.replace(/ /g, "%20");
if (navigator.msSaveOrOpenBlob) {
const blob = new Blob(["ufeff", tableHTML], {
type: dataType,
});
navigator.msSaveOrOpenBlob(blob, filename);
} else {
downloadLink.href = "data:" + dataType + ", " + tableHTML;
downloadLink.download = filename;
downloadLink.click();
}
thanks in advance.
question from:
https://stackoverflow.com/questions/66061704/html-table-to-excel-conversion-error-on-open-the-file-as-extention-xls-do-not 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…