There are multiple JS libraries that allow export to excel. But what if we want to follow a minimalist approach avoiding extra dependencies.
The simplest approach would be to produce CSV from JSON that can easily be opened in excel.
But before I show the conversion logic, let's understand what CSV is and which encoding we shall use when creating a CSV file.
This RFC 4180 Common Format and MIME Type for Comma-Separated Values (CSV) Files specifies definition of the CSV format. Note that this is a memo only as the CSV format is not officially standardized.
In my JSON data I have characters æ å ø from ISO Latin-1 (ISO/IEC 8859-1) character set that have to be considered when creating a csv file.
Some excerpts The Unicode® Standard Version 15.0 to consider.
From The Unicode® Standard Version 15.0:
In short, adding zero width no-break space before the CSV string will enforce Excel to apply UTF-8 encoding instead of 1252: Western European (Windows) or some other encoding which Excel will choose in case the U FEFF character is not provided.
I will show the difference between producing CSV file with zero width no-break space and without it in the next post of this series...
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3