Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I write xlsx to file in browser with ExcelJS?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading