I am trying to create an xlsx file in the browser and find https://github.com/exceljs/exceljs very powerful. However, I can’t find a way how to save my xlsx object to a file. Probably I need to use Buffer, but how to generate a file from it?
const buffer = await workbook.xlsx.writeBuffer();
This library can generate files in the browser https://docs.sheetjs.com/docs/ but it is not good at building complex fields.
>Solution :
To save the xlsx file in the browser with ExcelJS, you can use the saveAs method. This method allows you to save a file from a JavaScript program in the browser.
Here is an example:
const workbook = new Excel.Workbook();
// Add data to the workbook
const buffer = await workbook.xlsx.writeBuffer();
const fileSaver = require('file-saver');
fileSaver.saveAs(new Blob([buffer]), 'my-file.xlsx');