Cells that contain "0%" appear blank in Excel

Cells that contain "0%" appear blank in Excel

yusussyususs Posts: 3Questions: 1Answers: 0
edited June 2017 in Free community support

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.

Answers

  • HPBHPB Posts: 73Questions: 2Answers: 18
    edited June 2017

    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:

            if(opts.text ) {
                tempNode.appendChild( doc.createTextNode( opts.text ) );
            }
    

    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 ) + '';

  • yusussyususs Posts: 3Questions: 1Answers: 0

    Thanks for your reply. But quickest fix didnt work for me.

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    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 be if ( opts.text !== undefined && opts.text !== null ).

    Also take a properly look as soon as possible though.

    Allan

  • HPBHPB Posts: 73Questions: 2Answers: 18

    @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 ) {

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    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

  • HPBHPB Posts: 73Questions: 2Answers: 18

  • yusussyususs Posts: 3Questions: 1Answers: 0

    @HPB
    I changed line(btw mine is 507) and didnt break the code. Also didnt resolve the issue

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    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

  • geethunimeshgeethunimesh Posts: 25Questions: 9Answers: 0

    a quick fix can be adding a space before "%". Like "0 %".

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    Buttons 1.5.0 is now available which addresses this issue. Using a space would also workaround the problem.

    Allan

This discussion has been closed.