Copy link to clipboard
Copied
Hi All,
I can able to read the CSV file. But I can't read the .xlsx file. Could anyone tell me how to read that?
var csvFile = File("~/Downloads/data.xlsx");
csvFile.encoding = 'UTF8'; // set to 'UTF8' or 'UTF-8'
csvFile.open("r");
var csvContent = csvFile.read();
csvFile.close();
Thanks.
Copy link to clipboard
Copied
Long answer: No
Short answer: save your *.xlsx as tab delimited *.txt and read this *.txt
Copy link to clipboard
Copied
Not in ECMAScript 3 (JSX), which predates the dinosaurs. (Technically not impossible, but you’d have to write everything from scratch and it’s quicker just to go mad.)
There are several XLSX parsing libraries for Node.js if you don’t mind using Node/CEP (or UXP, once that ships). Just search on NPM.
However, expect to run into various gotchas when reading cells that use text styles, automatic number and date formatting, and other Excel features. What Excel displays on screen is not necessarily how that data is stored in the file. Not so much an issue when using Excel files in Excel as mathematical spreadsheets, as they were meant to be used. But a source of excitingly unanticipated bugs when reading XLSX files from customers who like to use them as ersatz databases. (e.g. Barcode numbers that start with “0”, which Excel will happily discard on cells that aren’t explicitly set to TEXT format.)
Otherwise, use Excel to export your spreadsheet file to .csv or .txt plaintext format, which bring their own sets of issues but are at least comparatively simple (relative to .xlsx) to parse and troubleshoot.