Export to Excel Button

Export to Excel Button

LamorakLamorak Posts: 3Questions: 1Answers: 0

Hello,

I am using the Export to Excel button option, however when I have more than 140 rows in my table, I get the following error:

Replaced Part: /xl/worksheets/sheet1.xml part with XML error. The name in the end tag of the element must match the element type in the start tag. Line 1, column 28983.

Has anyone encountered this before? Dropping down to 139 rows lets the table export properly so I don't think its a Data issue. Here is all I am doing for the button.

"buttons": [ {extend:'excel', title:'DealTrackerExport', exportOptions: {stripNewlines:true, stripHtml:true} }],

Sorry for the poor code formating and thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,195Questions: 1Answers: 10,413 Site admin

    Can you link to the page showing the issue so I can debug it please. Could you also try the nightly version of Buttons which might result this issue.

    Allan

  • LamorakLamorak Posts: 3Questions: 1Answers: 0
    edited January 2016

    Hi Allan,

    Sorry for the long delay, I was off for the holidays and forgot to check back here. The good news is, I have tracked the error to a data problem. Where there is a new line in my data, it causes Excel to fail to open the file.

    However, these are my export options, so I would expect it to remove the new line

    "buttons": [ { extend:'excel', title:'DealTrackerExport', exportOptions: { stripNewlines:true, stripHtml:true, columns: ':visible' } } ],

    Also I tried adding in the nightly version but it didn't fix my issue.

    Thanks!

  • allanallan Posts: 63,195Questions: 1Answers: 10,413 Site admin

    Could you give me a link to the page so I can debug and fix the issue please. I'd like to release a new version of Buttons - if not today, then tomorrow, and it would be good to get this fix in.

    Allan

  • LamorakLamorak Posts: 3Questions: 1Answers: 0

    Hi Allan,

    I figured out my error, as you might have guessed it was on my side. There was some code that creates each cell in the datatable that looks like
    return "<div class='dataViewSpn pull-left' title='" + output + "' >" + output + "</div>";

    However, some data had newlines in it which caused the div.title attribute to contain new lines, so when the strip HTML function ran during export, it only took part of the tag. The partial tag caused Excel to throw the error. To fix I added
    replace(/\r?\n|\r/g, ' ' ) to the output in the title tag.

  • allanallan Posts: 63,195Questions: 1Answers: 10,413 Site admin
    Answer ✓

    Interesting. That's not so much an error on your part I feel, but rather a limitation of using regex to try and strip the HTML tags. I will look at trying to improve that.

    Thanks for letting me know your findings!

    Allan

This discussion has been closed.