Export Excel files client-side with JavaScript

Paulo Levy
An Idea (by Ingenious Piece)
1 min readJul 24, 2020

--

Being able to export spreadsheet files such as .xls, .csv, .xlsx, etc, on the client is a pretty cool feature and can be easily implemented using JavaScript.

To achieve such a task, I'll use an approach that requires installing the following libraries:

file-saver: Solution to saving files on the client-side.
xlsx: Parser and writer for various spreadsheet formats.

npm install file-saver xlsx

Create a function to receive the desired data to be written to a spreadsheet. I named it exportSpreadsheetFile.js and it will generate a .xlxs file.

Function to export .xlsx file from provided data.

This approach uses the Array of Arrays method, which I find pretty straight forward:

The function takes an array object and each array inside of it will become a row. To illustrate, here's an example:

Sample Array of Arrays data being exported to .xlsx file

That's it, now you just have to import and use the exportToSpreadsheet function created, passing the desired data and the file name.

--

--

Paulo Levy
An Idea (by Ingenious Piece)

Co-founder at Shipny Studio. ​A dedicated tech innovation team for your business. www.shipny.studio