Excel / Copy buttons - Keep formatting in some cells

Excel / Copy buttons - Keep formatting in some cells

guidolsguidols Posts: 38Questions: 14Answers: 1
edited August 2022 in Buttons

I'm using the Excel / Copy buttons, which are working fine for most situations.

However I have a situation where a particular column contains html data, which is then rendered, please see these simple cells:

If I export that table, the Excel (or copy) button will create a cell containing:


Is ok that only a cell is created, but how can I tell the button to insert in the cell the new line break character?

This question has an accepted answers - jump to answer


  • rf1234rf1234 Posts: 2,856Questions: 85Answers: 409

    This thread might help you out.
    Warning: Customizing the client side Excel export can be very cumbersome and complex! Data tables does have some styles built in but you may end up having to create your own, for example

  • allanallan Posts: 62,484Questions: 1Answers: 10,262 Site admin

    The export gets it's data from the buttons.exportData() method. Which by default will strip HTML and new lines.

    What you want to do is set the stripNewlines option to false for the exportOptions object in your export button:

      extend: 'copy',
      exportOptions: {
        stripNewlines: false


  • guidolsguidols Posts: 38Questions: 14Answers: 1
    edited August 2022

    I added, in my html data, the character that Excel uses to add a new line in a cell, i.e. char(10).

    But there is still a problem: the user creates the Excel using the buttons and, after opening it, he needs to press the "wrap text" button in the column containing the wrapped data:

    Without doing so, the data is not wrapped.

    Is there a way to create the Excel and "forcing" wrapping data?

    Please see this similar problem and solution (non related to DataTables):

    "After you supply text you should set the cell's IsTextWrapped style to true".


  • kthorngrenkthorngren Posts: 20,793Questions: 26Answers: 4,860
    edited August 2022 Answer ✓

    This thread discusses one option.


  • guidolsguidols Posts: 38Questions: 14Answers: 1

    Thanks Kevin!

    This will do the trick (where "F" is the desired column):

    $('row c[r^="F"]', sheet).attr('s', '55');

Sign In or Register to comment.