Cells that contain "0%" appear blank in Excel
Cells that contain "0%" appear blank in Excel
yususs
Posts: 3Questions: 1Answers: 0
Hi to everyone
My datatable result is;
0 0 0 10%
0 0 0 0%
40 280 320 16%
but excel showing when I export;
0 0 0 10%
0 0 0 <-- 0% missing
40 280 320 16%
How can i fix this?
Have a nice day.
This discussion has been closed.
Answers
This is currently a bug. I don't know when Allan has time to fix it, but it should be soon since I found out why.
@allan
I've did some digging and found what is causing it.
_excelSpecials
is returning a number instead of a string when it matches a percentage.Then it continues to pass this number into the
_createNode
function.And then it does this:
opts.text
will test false for a number with value 0 and it will never add the text node.You probably know best what the cleanest fix is. Either forcing a string value as input or testing for numbers.
quickest fix is to change line 1074 of buttons.html5.js
val = special.fmt( val );
with
val = special.fmt( val ) + '';
Thanks for your reply. But quickest fix didnt work for me.
This thread also discusses this issue.
Thanks for your digging @HPB! I haven't looking into it yet, but I suspect it might be that the
if
statement you identified should beif ( opts.text !== undefined && opts.text !== null )
.Also take a properly look as soon as possible though.
Allan
@allan
Not likely, but someone could create a variable called
undefined
and it will break the code.I was thinking of
if ( opts.hasOwnProperty('text') && opts.text !== null )
@yususs
What happens if you change line 592
From:
if( opts.text ) {
To:
if( opts.hasOwnProperty('text') && opts.text !== null ) {
That won't be the only place in DataTables that things break if someone overrides
undefined
!Have you come across this before? Makes me laugh every time I think about it .
Allan
@HPB
I changed line(btw mine is 507) and didnt break the code. Also didnt resolve the issue
I've just committed the required fix and it seems to work well here.
The nightly will update shortly. Could you try that please?
Thanks,
Allan
a quick fix can be adding a space before "%". Like "0 %".
Buttons 1.5.0 is now available which addresses this issue. Using a space would also workaround the problem.
Allan