Export Excel/PDF : Add legend multi line

Export Excel/PDF : Add legend multi line

xavstargatexavstargate Posts: 4Questions: 1Answers: 0

How make this ?
Use messageBottom/messageTop ?

Doesn't work in Excel for multi line, "\n" doesn't work properly, but it's work in PDF :|

Thanks !

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736
    Answer ✓

    Excel doesn't use \n for newlines. Unfortunately, due to the format of the XML file Excel and other spreadsheets use, it is not a simple task to insert newlines within the text. To use newlines with the Datatables Excel export the following steps are needed for each cell:

    1. Use the CONCATENATE and CHAR functions to build the string with newlines, example: CONCATENATE("Line 1", CHAR(13), "Line 2")
    2. Change the cell type to formula
    3. Change the formatting of the cell to include word wrap

    This thread explains how to do this for the data portion that is exported:
    https://datatables.net/forums/discussion/41778

    I'm not sure if the messageTop and messageBottom options support applying the styles from the style sheet in the same way the data area does.

    Kevin

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    You can use style 55 which is built into the XSLX file generated by Buttons to cause \n to display as new lines - see the excelHtml5 documentation and also this example for how to change the style of a cell.

    I'm not sure if the messageTop and messageBottom options support applying the styles from the style sheet in the same way the data area does.

    Yup :).

    Allan

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    Oh - One other thing. You have to disable the stripping of new line characters in the export options for the button - otherwise they will just be removed!

    Allan

  • xavstargatexavstargate Posts: 4Questions: 1Answers: 0

    Thanks :)

  • seabassseabass Posts: 5Questions: 1Answers: 0

    How do you "disable the stripping of new line characters"? Thank you!

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    See stripNewlines option here ,

    Colin

  • seabassseabass Posts: 5Questions: 1Answers: 0

    Ok, I'm now running stripNewlines: false in my excel export, but there are still no linebreaks in my messageTop. It seems like "\n" is still getting stripped. Any workarounds?

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.