1 回答
TA贡献1856条经验 获得超17个赞
你的意图是正确的,代码是错误的。您正在定义数据并将其推送到数组中,而不是创建 JSON 对象。尝试这个。
var to_json_linebyline = function to_json_linebyline(wb){
var sheet = wb.Sheets['Sheet1'];
var results = [];
var range = XLSX.utils.decode_range(sheet['!ref']);
for(let rowNum = (range.s.r+1); rowNum <= range.e.r; rowNum++){
let thisRow = {},
thisNode = '';
for(let colNum=range.s.c; colNum<=range.e.c; colNum++){
var thisHeader = sheet[XLSX.utils.encode_cell({r: 0, c: colNum})].w
var thisCell = sheet[XLSX.utils.encode_cell({r: rowNum, c: colNum})].w
if(colNum === 0){
thisNode = thisCell;
}
thisRow[thisHeader] = thisCell;
}
thisResult = {};
thisResult[thisNode] = [thisRow]
results.push(thisResult)
}
return JSON.stringify(results);
}
添加回答
举报