JavaScript(节点js)在读取Excel文件时跳过空单元格

我正在做一个小的任务来读取Excel工作表并保存为json格式。 我使用的代码在所有单元格值存在的情况下运行良好,如果有空单元格跳过该单元格。

如果没有提供任何值(在我的情况下,我错过了cust2电话号码),我想要的输出如下。

[ { cust_name: 'Ben', cust_city: 'Street1', cust_country: 'country1', phno: 1 }, { cust_name: 'Ken', cust_city: 'street2', cust_country: 'country2' phno:}, { cust_name: 'Ron', cust_city: 'street3', cust_country: 'country3', phno: 3 } ]

但是我得到的输出是

[ { cust_name: 'Ben', cust_city: 'Street1', cust_country: 'country1', phno: 1 }, { cust_name: 'Ken', cust_city: 'street2', cust_country: 'country2' }, { cust_name: 'Ron', cust_city: 'street3', cust_country: 'country3', phno: 3 } ]

它错过了提供phno的phno。

请帮助我找出我的代码中需要更改的内容以获得所需的输出。

我的代码是

  var XLSX = require('xlsx'); var workbook = XLSX.readFile('customer.xlsx'); var sheet_name_list = workbook.SheetNames; sheet_name_list.forEach(function(y) { var worksheet = workbook.Sheets[y]; var headers = {}; var data = []; for(z in worksheet) { if(z[0] === '!') continue; //parse out the column, row, and value var col = z.substring(0,1); var row = parseInt(z.substring(1)); var value = worksheet[z].v; //store header names if(row == 1) { headers[col] = value; continue; } if(!data[row]) data[row]={}; data[row][headers[col]] = value; } //drop those first two rows which are empty data.shift(); data.shift(); console.log(data); }); 

提前致谢!!