Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel value exported as undefined for non existing key only if cellstyle is associated for column specification #59

Open
joyblanks opened this issue Jun 1, 2021 · 0 comments

Comments

@joyblanks
Copy link

joyblanks commented Jun 1, 2021

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'},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant