With ember I am currently letting the user upload files through the ember-file-upload package and trying to parse excel files with the xlsx package but I can't seem to get them to work together. I have gotten other packages to convert the file to csv, json, etc. but can't seem to get the excel file upload to convert with xlsx and I can't seem to find any other packages that work.
I am currently trying to do it this way but it always appears empty.
file.onloadstart = function (e) {
alert("started reading");
}
file.onload = function (e) {
// pre-process data
var binary = "";
var bytes = new Uint8Array(e.target.result);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) {
binary += String.fromCharCode(bytes[i]);
}
// call 'xlsx' to read the file
var workbook = XLSX.read(binary, {type: 'binary', cellDates:true, cellStyles:true});
//return oFile;
alert(workbook.SheetNames.length);
alert(workbook.SheetNames[0]);
var worksheet = workbook.Sheets[workbook.SheetNames[0]];
var desiredCell = worksheet['A1'];
var desiredValue = (desiredCell ? desiredCell.v : undefined);
alert(desiredValue);
};
file.readAsArrayBuffer().then(function(data) {
alert(XLSX.utils.sheet_to_csv(data));
csv2geojson.csv2geojson(data, function(err, jsondata) {
// do something
});
});
Currently file.onloadstart never gets called and neither does file.onload but when I tested outside of those the workbook.SheetNames.length alerts the wrong length the workbook.SheetNames[0] gives a bad sheetname and the desiredValue alert is blank along with alerting XLSX.utils.sheet_to_csv(data) alert is blank and with length 0.
Aucun commentaire:
Enregistrer un commentaire