officegen
officegen copied to clipboard
Null Handling in Excel Sheet
Environment
-
node -v
: v12.14.1 -
npm -v
: 6.13.6 -
npm ls officegen
: -- [email protected] - Operating system: Windows 10
- Microsoft Office version: 2016
- Problem with Powerpoint, Excel or Word document: Excel
Steps to Reproduce
const officegen = require("officegen");
const fs = require("fs");
const xlsx = officegen("xlsx");
const sheet = xlsx.makeNewSheet();
sheet.data[0] = ["Some String", null, 0];
sheet.data[1] = ["Some String", undefined, 0];
const out = fs.createWriteStream("test.xlsx");
xlsx.generate(out);
Expected Behavior
I would expect that null would produce an empty string, and be handled the same way as undefined.
Actual Behavior
Null results in the value 0
In column A2 the value is null, column B2 is undefined. I would expect these to share the same behavior.
The relevant code is https://github.com/Ziv-Barber/officegen/blob/master/lib/xlsx/genxlsx.js#L477 to fix would just need to explicitly handle the null case. I can put a PR together, but wanted to start with an issue in case this is intended behavior.
The reason this comes up is we are populating the sheet from a db query, so the null comes straight out of the DB. A null value has a different meaning then a 0 in this context.
I'll fix it for you
Awesome thanks