Breaklines on cell not showing on excel

Breaklines on cell not showing on excel

davidmesguerradavidmesguerra Posts: 2Questions: 1Answers: 0

I have a table and it works fine with DT, but, I also use the Excel export button, the problem is, excel ignores "<br> tag, this is my html table:

****
# Registro Conexiones/Recargas Dispositivos
1 Dann2021-02-10 17:06:26
1970-07-06 11:32:28
SO:Windows10 Nav:Chrome
SO:Windows10 Nav:Mozilla

The td tags with IDs xxxxx-data-20 haves info with breaklines, the Excel file is ignoring this
I also tried using divs, table inside table, all works fine on browser, but the breakline is totally ignored on the Excel exported file, any sugestions?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,328Questions: 26Answers: 4,949
    Answer ✓

    See this thread for an example of how to show newlines in Excel.

    Kevin

  • davidmesguerradavidmesguerra Posts: 2Questions: 1Answers: 0

    Great, the data.replace function did the trick (Also, the users need to apply the "wrap text" button on the excel file)

  • kthorngrenkthorngren Posts: 21,328Questions: 26Answers: 4,949

    The customize function in the thread will set the cells for wrap text.

    customize: function( xlsx ) {
        var sheet = xlsx.xl.worksheets['sheet1.xml'];
        var col = $('col', sheet);
        //set the column width otherwise it will be the length of the line without the newlines
        $(col[3]).attr('width', 50);
        $('row c[r^="D"]', sheet).each(function() {
            if ($('is t', this).text()) {
                //wrap text
                $(this).attr('s', '55');
                //change the type to `str` which is a formula
                $(this).attr('t', 'str');
                //append the concat formula
                $(this).append('<f>' + $('is t', this).text() + '</f>');
                //remove the inlineStr
                $('is', this).remove();
            }
        })
    },
    

    Kevin

This discussion has been closed.