Reputation: 41
I am using sheetjs. The empty cell is not getting populated in the json object including the header. I need that information also if a column is not entered. Here is my code:
workbook.SheetNames.forEach((sheetName) => {
let XL_row_object = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], {defval:""});
console.log( JSON.stringify(XL_row_object ));
}
Upvotes: 4
Views: 6441
Reputation: 422
To extend the sheetStubs
answer, XLSX.utils.sheet_to_json
will ignore stubs so you should first convert them with a simple function:
function removeStubs(wb) {
Object.values(wb.Sheets).forEach(ws => {
Object.values(ws).filter(v => v.t === 'z').forEach(v => Object.assign(v,{t:'s',v:''}));
});
return wb;
}
then call
removeStubs( XLSX.readFile('file', {sheetStubs:true}) )
Upvotes: 0
Reputation: 405
You can solved it with this part, at the begining, when you are including your SheetJS:
**const data = xlsx.utils.sheet_to_json((ws),{defval:""});**
Upvotes: 7
Reputation: 53
I was having the same issue and I solved this problem with this:
XLSX.readFile('file', {sheetStubs:true})
Upvotes: 1