node-excel-export
node-excel-export copied to clipboard
Excel value exported as undefined for non existing key only if cellstyle is associated for column specification
Consider the following snippet to replicate the issue:
Environment NodeJS v13 +
import excelExport from 'node-excel-export';
const specification = {
col1: {displayName: 'COL1', cellStyle: { fill: { fgColor: { rgb: 'FF57b370' } } } },
col2: {displayName: 'COL2'},
};
const data = [
{col1: 'some data1', col2: 'some data2'},
{col1: 'some data1'},
{col2: 'some data2'},
{},
{col1: undefined, col2: undefined}
];
excelExport.buildExport([{ name: 'Report', specification, data }]);
Current Output (ISSUE): In the excel it exports undefined as text for col1 where col1 value is not there or a non existent key/value property is not there or value is undefined, but works fine for col2 since it has no cellStyle associated.
| COL1 | COL2 |
|---|---|
| some data1 | some data2 |
| some data1 | |
| undefined | some data2 |
| undefined | |
| undefined |
Expected Output: If cell is undefined or not present as key, should export empty cell irrespective of styles added
| COL1 | COL2 |
|---|---|
| some data1 | some data2 |
| some data1 | |
| some data2 | |
As a workaround for now I am using cellFormat to manually reset the value where cellstyle is applicable
const specification = {
col1: {displayName: 'COL1', cellStyle: { fill: { fgColor: { rgb: 'FF57b370' } } }, cellFormat: (v,r) => v===undefined?'':v },
col2: {displayName: 'COL2'},
};