xlsx-template-ex
xlsx-template-ex copied to clipboard
0 mapping as blank
Hi there!
I've been experimenting with the library here a little bit, and have found that if I have a Number
coming in, and map it to a cell in my template which is formatted with a number format (Number, Percentage, Accounting, etc) it maps fine - unless it is a 0.
For an example, if I have this json (test.json
):
'summary':
[ { advances: 1234.56, payments: -1234.56, adjustments: 0, transfers: 0 } ]
And in my template (example.xlsx
) have:
[[summary|repeat-rows:4]]{{advances}}
{{payments}}
{{adjustments}}
{{transfers}}
after running it through xlsxBuildByTemplate(test.json, example.xlsx);
{{advances}}
will show 1234.56, {{payments}}
will show -1234.56; but adjustments and transfers will both be blank.
Here is an image of what I mean.
However, if I input them all as String
, everything fills in as expected (0s included); but then the formatting in the output/templated document is incorrect.
I have been adjusting library code on a local branch; but haven't yet figured it out. Any help would be appreciated! Thanks =]
I've narrowed it down to line 67 of template-engine.js
let resultValue = data[tplExp.valueName] || '';
It is reaching the other condition ( ... || '';
) and parsing 0
values the same as it would a null value when attempting to set the cell.value
Created a quick PR if y'all want to check it out =]
#13