I export a JSON array to Excel using JavaScript. However, Excel shows a warning popup on open. How can I prevent this? Revised code example follows:
function exportToSpreadsheet(dataArray) {
const headerLine = Object.keys(dataArray[0]).join(',') + '\n';
const dataLines = dataArray.map(item => Object.values(item).join(',')).join('\n');
const fileContent = headerLine + dataLines;
const fileBlob = new Blob([fileContent], { type: 'application/vnd.ms-excel' });
const downloadElem = document.createElement('a');
downloadElem.href = URL.createObjectURL(fileBlob);
downloadElem.download = 'ExportedFile.xlsx';
downloadElem.click();
}