officegen icon indicating copy to clipboard operation
officegen copied to clipboard

Null Handling in Excel Sheet

Open mrawdon opened this issue 4 years ago • 2 comments

Environment

  1. node -v: v12.14.1
  2. npm -v: 6.13.6
  3. npm ls officegen: -- [email protected]
  4. Operating system: Windows 10
  5. Microsoft Office version: 2016
  6. 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.

image


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.

mrawdon avatar Apr 01 '20 14:04 mrawdon

I'll fix it for you

Ziv-Barber avatar Apr 03 '20 19:04 Ziv-Barber

Awesome thanks

mrawdon avatar Apr 03 '20 19:04 mrawdon