Possible to insert new line / break in messageTop?

Possible to insert new line / break in messageTop?

relish27relish27 Posts: 11Questions: 2Answers: 0

Hello,
I have header and footer legend notes that I'd like to append to my exported XLS file. I was thinking that I could somehow include "\n" and then they'd go to the next line, even if all the text was in one cell. Is that possible?

I have tried a few things I've seen people try:

                        exportOptions: {
                            stripNewlines: false
                        },  

And:

            var data = output_table.buttons.exportData( {
                modifier: {
                    stripNewlines: false,
                    stripHTML: false
                }
            } );    

But I'm not having any luck. Is this possible? I'd love to have a list of items in the footer (or header) if I can.

This question has an accepted answers - jump to answer

Answers

  • relish27relish27 Posts: 11Questions: 2Answers: 0

    Turns out I actually needed just to get my text wrapping. The text was already in list form, but without text-wrapping, they were getting mooshed together on one line. So, first I did this:

                                // wrap legend text
                                $('row:nth-child(2) c', sheet).eq(0).attr('s', '55');
    

    And then it was working, but it appeared the text was missing, as the text was vertically aligned to the bottom. I don't exactly get it, but I was able to use this example to get it to align better: https://datatables.net/forums/discussion/comment/108872/#Comment_108872

                            customize: function( xlsx ) {
    
                                var ocellXfs = $('cellXfs', xlsx.xl['styles.xml']);
                                ocellXfs.append('<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyFont="1" applyFill="1" applyBorder="1" applyAlignment="1">'+'<alignment vertical="top" wrapText="1" />'+'</xf>');
                                ocellXfs.attr('count', ocellXfs.attr('count') +1 );
                                var oxf = $('xf', xlsx.xl['styles.xml']);
                                var styleIndex = oxf.length;
    
                                var sheet = xlsx.xl.worksheets['sheet1.xml'];
    
                                // top vertical alignment
                                $('row:nth-child(2) c', sheet).eq(0).attr('s', styleIndex - 2);
    
    

    I then decided to increase the height of my "legend" row so that people would know it was there -- even if they did need to increase the height.

                                // set height
                                $('row:nth-child(2)', sheet).attr('ht', '300');
                                $('row:nth-child(2)', sheet).attr('customHeight', 1);
    
    

    All together, this is the start of my "customize" property:

                            customize: function( xlsx ) {
    
                                var ocellXfs = $('cellXfs', xlsx.xl['styles.xml']);
                                ocellXfs.append('<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyFont="1" applyFill="1" applyBorder="1" applyAlignment="1">'+'<alignment vertical="top" wrapText="1" />'+'</xf>');
                                ocellXfs.attr('count', ocellXfs.attr('count') +1 );
                                var oxf = $('xf', xlsx.xl['styles.xml']);
                                console.log(oxf);
                                var styleIndex = oxf.length;
                                var sheet = xlsx.xl.worksheets['sheet1.xml'];
    
                                //console.log(sheet);
                                var row = 0;
    
                                //console.log("header legend: " + $('row:nth-child(2) c', sheet).text());
    
                                // wrap legend text
                                $('row:nth-child(2) c', sheet).eq(0).attr('s', '55');
    
                                // top vertical alignment
                                $('row:nth-child(2) c', sheet).eq(0).attr('s', styleIndex - 2);
    
                                // set height
                                $('row:nth-child(2)', sheet).attr('ht', '300');
                                $('row:nth-child(2)', sheet).attr('customHeight', 1);
    
    }
    
  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    You've been busy, it sounds like you've made progress and resolved your issue, but shout if we can help.

  • relish27relish27 Posts: 11Questions: 2Answers: 0

    @colin Thank you!

This discussion has been closed.