[英]First value is missing in excel file in XLSX JS
我正在尝试使用插件 xlsx.js 读取 Javascript 中的 excel 文件。 我可以读取除第一个值之外的所有单元格值。 这是我的代码:
让 numArr = [];
selectFile(event) { let reader = new FileReader();
reader.onload = () => { const data = reader.result; const workbook = XLSX.read(data, { type: 'binary' }); workbook.SheetNames.forEach((sheetName) => { // Here is your object const XL_row_object = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]); // var json_object = JSON.stringify(XL_row_object); for (let i = 0; i < XL_row_object.length; i++) { // this.groupNumsArr.push(XL_row_object[i]['number']); const theNum = Object.values(XL_row_object[i])[0].toString(); numArr.push(theNum); } }); }; reader.readAsBinaryString(event.target.files[0]); }
api 将第一行作为键,所以你可以试试这个
for (let i = 0; i < XL_row_object.length; i++) {
var theNum = '';
if(i == 0)
{
theNum = Object.keys(XL_row_object[i])[0].toString();
numArr.push(theNum);
}
// this.groupNumsArr.push(XL_row_object[i]['number']);
theNum = Object.values(XL_row_object[i])[0].toString();
numArr.push(theNum);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.