to_json function in http://oss.sheetjs.com/js-xlsx is not correct #896

Closed
opened 2017-11-22 07:48:18 +00:00 by tsbxmw · 1 comment
tsbxmw commented 2017-11-22 07:48:18 +00:00 (Migrated from github.com)
  • reason
    when i use the javascript of the "http://oss.sheetjs.com/js-xlsx" ,
    1, choose the "Output Format:" to JSON
    2, click the button "or click here to select a file" to import one xlsx file
    3, i get the result that is not expected.

so i change the to_json function with the script of http://oss.sheetjs.com/, then it works good.

the to_json function should be :

    var to_json = function to_json(workbook) {
	if(useworker && workbook.SSF) XLSX.SSF.load_table(workbook.SSF);
	var result = {};
	workbook.SheetNames.forEach(function(sheetName) {
		var roa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], {header:1});
		if(roa.length > 0) result[sheetName] = roa;
	});
	return result;
    };
* reason when i use the javascript of the "http://oss.sheetjs.com/js-xlsx" , 1, choose the "Output Format:" to JSON 2, click the button "or click here to select a file" to import one xlsx file 3, i get the result that is not expected. so i change the to_json function with the script of http://oss.sheetjs.com/, then it works good. the to_json function should be : ```javascript var to_json = function to_json(workbook) { if(useworker && workbook.SSF) XLSX.SSF.load_table(workbook.SSF); var result = {}; workbook.SheetNames.forEach(function(sheetName) { var roa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], {header:1}); if(roa.length > 0) result[sheetName] = roa; }); return result; }; ```
SheetJSDev commented 2017-11-22 15:53:23 +00:00 (Migrated from github.com)

The default behavior is to assume the first row contains header data, which is why it looks weird if the sheet isn't properly structured. The header:1 option generates an array of arrays.

Feel free to submit a Pull Request :) http://oss.sheetjs.com/js-xlsx is hosted in the gh-pages branch: https://github.com/SheetJS/js-xlsx/blob/gh-pages/index.html#L78 is the relevant code segment

The default behavior is to assume the first row contains header data, which is why it looks weird if the sheet isn't properly structured. The `header:1` option generates an array of arrays. Feel free to submit a Pull Request :) http://oss.sheetjs.com/js-xlsx is hosted in the gh-pages branch: https://github.com/SheetJS/js-xlsx/blob/gh-pages/index.html#L78 is the relevant code segment
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#896
No description provided.