Ziv-Barber / officegen

Standalone Office Open XML files (Microsoft Office 2007 and later) generator for Word (docx), PowerPoint (pptx) and Excell (xlsx) in javascript. The output is a stream.
MIT License
2.65k stars 471 forks source link

Null Handling in Excel Sheet #355

Open mrawdon opened 4 years ago

mrawdon commented 4 years ago

Environment

  1. node -v: v12.14.1
  2. npm -v: 6.13.6
  3. npm ls officegen: -- officegen@0.6.3
  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.

Ziv-Barber commented 4 years ago

I'll fix it for you

mrawdon commented 4 years ago

Awesome thanks