natergj / excel4node

Node module to allow for easy Excel file creation
MIT License
1.38k stars 215 forks source link

TypeError: Cannot read property 'match' of null #218

Closed aavanzyl closed 6 years ago

aavanzyl commented 6 years ago

When adding a null value to a cell, you get an TypeError: Cannot read property 'match' of null error.

Example

var xl = require('excel4node');

//Create Workbook
var wb= new xl.Workbook();
let sheet1= wb.addWorksheet('Test');
sheet1.cell(1,1).string('Test');

//set empty cell
sheet1.cell(2, 1).string(null);

I expected the lib to handle null values or give a more descriptive error when they happen.

natergj commented 6 years ago

I'm going to mark this as a bug. I think the best solution for this one would be to forcibly coerce any value sent to cell.string() to a string. This would print out the word "null" in the cell when the method is passed a null value. This would also would put strings like "undefined" and "[object Object]".

natergj commented 6 years ago

it turns out I had already had code to handle non-string values being passed to the string method but a bug was preventing that code from being applied. That is resolved in version 1.5.1. non-string values will be replaced with empty strings and a warning will be logged to the console if the workbook was initialized with a log level above warn.

aavanzyl commented 6 years ago

Awesome man, great that you where able to find and fix it, This will help alot. Thank you