Sheetjs: XLSX.utils.sheet_to_json returning empty array

Created on 2 Mar 2018  路  3Comments  路  Source: SheetJS/sheetjs

Hey,

I am trying to give our users the possibility to upload an XLSX file (through ng-file-uploader), and to convert this XLSX file to JSON data afterwards.
The uploading of the file works fine, this is the result when I print $scope.file in the console:
screen shot 2018-03-02 at 10 08 16

When I try to use the sheet to json function, I get an empty array back, while there is a lot of data in the uploaded XLSX file.

In my code I use the following:
XLSX.utils.sheet_to_json($scope.file);

This returns an empty array as said before.
Is there something I'm forgetting or should execute differently?

Kind regards,

Thomas

Most helpful comment

@Xsmael I solved this setting a the name of the sheet you want to use and also the header, which might help you to identify each column.

var workbook = XLSX.read(bstr, {type:'binary'});
var form = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[3]], {header:["headerName1","headerName2","headerName3"]});

Where workbook.SheetNames[3] is the name of my third sheet, which is the one I'm using in this example.
I hope this helps you

All 3 comments

Update: I got the file into the XLSX tool now. I was able to create the workbook, but now I'm trying to use the XLSX.utils.sheet_to_json on one of the sheets inside the workbook in the following way, and I'm getting an error:
var roa = XLSX.utils.json_to_sheet(workbook.Sheets['1 LG woorden']);
The error:
screen shot 2018-03-02 at 11 00 51

This is my workbook object:
screen shot 2018-03-02 at 11 02 47

how did you solve this ? am having the same issue on nodejs

@Xsmael I solved this setting a the name of the sheet you want to use and also the header, which might help you to identify each column.

var workbook = XLSX.read(bstr, {type:'binary'});
var form = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[3]], {header:["headerName1","headerName2","headerName3"]});

Where workbook.SheetNames[3] is the name of my third sheet, which is the one I'm using in this example.
I hope this helps you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sudhakar-sekar picture sudhakar-sekar  路  3Comments

HachimDev picture HachimDev  路  3Comments

upasana-shah picture upasana-shah  路  4Comments

jamesbillinger picture jamesbillinger  路  4Comments

Alex0007 picture Alex0007  路  3Comments