Home » excel » javascript – How to upload and convert XLSX file to JSON using ember.js

javascript – How to upload and convert XLSX file to JSON using ember.js

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to allow the user to upload an XLSX file to be converted to a JSON or CSV file to be parsed through on the back-end. I am using node.js, and tried several packages including the read-excel-file
(https://github.com/catamphetamine/read-excel-file/blob/master/README.md)

readXlsxFile(file).then(function(data) {
let jsondata = JSON.parse(data);
-do something with jsondata-
});
How to&Answers:

The usual place to look for add-ons would be Ember Observer but the options available seem have a status of Work In Progress – they might be a useful place to look though to get some inspiration for how to proceed.

There are plenty of options on npm. You can import one of those into your project using the new add-on ember-auto-import or, if you’d rather do the hard work yourself, the Ember guides provide some guidance on manually importing.

Answer:

You can use js-xlsx. Add it as bower dependecy and add its imports to your ember-cli-build file as:

app.import('bower_components/js-xlsx/dist/jszip.js');
app.import('bower_components/js-xlsx/dist/xlsx.min.js');

Handle it as the documentation’s parsing-workbooks section shows. (handleFile function is explaining it well.)