I am able to read and process *.xlsx files using an input element of type file and the library exceljs. Also see example code below.
Unfortunately, exceljs does not seem to support open document spreadsheet files *.ods. (The worksheet is undefined).
=> How can I read and process *.ods files with javascript?
https://github.com/exceljs/exceljs
https://github.com/exceljs/exceljs/issues/716
static async readFile(file){
await this.__initializeExcel();
const workbook = new Excel.Workbook();
await workbook.xlsx.load(file);
const worksheet = workbook.worksheets[0];
var data = [];
const numberOfRows = worksheet.rowCount;
for (let rowIndex = 1; rowIndex <= numberOfRows; rowIndex++) {
const row = worksheet.getRow(rowIndex);
const rowValues = row.values;
data.push(rowValues);
rowValues.shift();
}
return data;
}
Related
Thanks to the comment of Brian I managed to read and process *.ods files with sheetjs/xlsx:
https://github.com/SheetJS/sheetjs
If you use script tags for import, please make sure to import
xlsx.full.min.jsinstead ofxlsx.min.js. Otherwise you'll get an errorCannot find file [Content_Types].xml in zip.