You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importExcelJSfrom'exceljs';constworkbook=newExcelJS.Workbook();constworksheet=workbook.addWorksheet('Sheet 1');worksheet.getCell('A1').value='Hello World';workbook.xlsx.writeBuffer().then((buffer)=>{constblob=newBlob([buffer],{type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',});consturl=window.URL.createObjectURL(blob);constanchor=document.createElement('a',{});anchor.href=url;constdocumentDate='2022-06-06';constdocumentTitle='Hello World';anchor.download=`${documentDate}${documentTitle}.xslx`;// the following results in normal behaviour// anchor.download = documentDate + " " + documentTitle + ".xslx";anchor.click();window.URL.revokeObjectURL(url);});
Adapt the above code to a button's onClick handler, and then click the button to see it in action.
The expected behaviour:
The file is downloaded and recognized to be an Excel file, such that the user can click on the file in their download history, and have the associated program (MS Excel, or LibreOffice Calc) open it.
Notes
Note that I'm using TypeScript, but I've inspected the generated JavaScript and didn't see any changes to the anchor.download line.
馃悰 Bug Report
When I use a string template literal as file name, the browser downloads the file as a binary blob:
It works when I use simple string concatenation
Lib version:
ExcelJS: 4.3.0
React: 18.1.0
TypeScript: 4.7.3
Browsers tested:
Chrome 102.0.5005.61
Firefox 100.0.2
All tests done on Linux (Intel 64-bit).
Steps To Reproduce
Adapt the above code to a button's
onClick
handler, and then click the button to see it in action.The expected behaviour:
The file is downloaded and recognized to be an Excel file, such that the user can click on the file in their download history, and have the associated program (MS Excel, or LibreOffice Calc) open it.
Notes
Note that I'm using TypeScript, but I've inspected the generated JavaScript and didn't see any changes to the
anchor.download
line.The above code was originally based on a comment by @dlinx in #354
The text was updated successfully, but these errors were encountered: