I use NodeJS for a lot of stuff. When I wanted to create an inventory system in JavaScript I considered the alternatives. Since the program is for personal use, writing a UI to edit the data had little value. I decided to use a spreadsheet. At first I used Google Sheets, but I was always exporting the file after saving it. Things would get out of sync. Very annoying and error prone.

As much as I’d rather use open source software, Excel is still the simplest solution. Unfortunately, Excel spreadsheets are XLSX files. XLSX is a rather complex XML format and difficult to parse. I looked for an NPM module to read XLSX files, but haven’t found one I liked.

After considerable head scratching, I realized R ( https://www.r-project.org/) is specifically designed to process tabular data from all sorts of sources. I decided to write a simple R script to do the conversion.

The readxl R package can read XLSX files into a table. Assuming the data does not contain a tab character, the table can be output to a Tab Separated Values (TSV) file. A TSV file is easy to parse in JavaScript.

#excel #programming #javascript #json

Processing Excel Files with JavaScript
2.15 GEEK