xlsx-template-ex icon indicating copy to clipboard operation
xlsx-template-ex copied to clipboard

0 mapping as blank

Open bassman2112 opened this issue 5 years ago • 2 comments

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 =]

bassman2112 avatar Oct 02 '19 01:10 bassman2112

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

bassman2112 avatar Oct 02 '19 14:10 bassman2112

Created a quick PR if y'all want to check it out =]

#13

bassman2112 avatar Oct 03 '19 17:10 bassman2112