Styling Last Row Excel Export

Styling Last Row Excel Export

chboccachbocca Posts: 90Questions: 14Answers: 1

I have a small issue with DataTables Buttons Excel Styling, a plugin that worked perfectly with dt1, but not dt2.

The last row of the table refuses to allow styling. I suspect it is because the code believes the last row is a footer, but I have no footer in the table ... just the last row.

Here is link to simple demo.

And here is link to same demo, but with dt1.

I tried setting footer: 'false' in exportOptions, but no effect.

Any suggestions? Should I create an empty last row before exporting?

I've reached out to the author as well.

Thanks, as always in advance.

c

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948

    That's quite a plugin. I haven't seen it before. I suspect the problem is with this function:

        /**
         * Get the index number of the last row in the worksheet
         *
         * @param {object} sheet Worksheet
         */
        var _getMaxSheetRow = function (sheet) {
            return Number($('sheetData row', sheet).last().attr('r'));
        };
    

    Some debugging of the plugin will need to take place to understand if this is the issue and why it seems to result in one less number of rows. As a workaround / test you could increment the returned result to see if it works, for example:

    return Number($('sheetData row', sheet).last().attr('r')) + 1;
    

    Kevin

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948
    Answer ✓

    I did a bit of experimentation and it looks like the code assumes there will be a footer even if setting footer: false. Some changes were made in DT 2 and the corresponding buttons to support multiple header rows. These changes probably affected the above statement's calculation.

    Further experimentation shows that the plugin also assumes a single header row. If you have two header rows then it will start formatting in the second header row not the first table row.

    I didn't try it but I believe the above change I suggested will provide a workaround for your particular situation but won't fix it for other header and footer configurations.

    Kevin

  • chboccachbocca Posts: 90Questions: 14Answers: 1

    Thank you, Kevin!

    Worked like a charm!

    Will forward to author as well.

    Very much appreciate your follow-up.

    c

  • allanallan Posts: 63,482Questions: 1Answers: 10,467 Site admin

    I don't think I've seen that plugin before either - it is fairly epic!

    Allan

Sign In or Register to comment.