Excel export doesn't format the column header like other columns when using option 50

Excel export doesn't format the column header like other columns when using option 50

iansriansr Posts: 13Questions: 3Answers: 0

https://live.datatables.net/ropoyema/1/edit

I'm trying to have all columns, including the header, left justified. Using option 50 does that for all but the header. How do I get the header to follow as well.

sheet.querySelectorAll('row c').forEach((el) => {
                            el.setAttribute('s', '50');

My test case for some reason I cannot figure out is not displaying the excel button. I did import the button js. The live app is on an intranet so I can't share a link there.

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    My test case for some reason I cannot figure out is not displaying the excel button

    First you are loading dataTables.buttons.js before jQuery resulting in this error in the browser's console:

    Uncaught ReferenceError: jQuery is not defined

    Second you need to define where to place the buttons using layout, topStart for example.

    Third you also need to load JSZip. The easiest way to get the proper files for the test case is to use the Download Builder.

    Here is the updated, running test case:
    https://live.datatables.net/ropoyema/2/edit

    It looks like all cells in the spreadsheet are left justified. Does the test case work for you?

    Possibly there is something specific with your data that Excel interprets differently resulting in cells that aren't left justified. Please post a link to your page or update the test case to show the issue so we can help debug.

    Kevin

  • iansriansr Posts: 13Questions: 3Answers: 0

    Thank you. Looking at the example and looking back at my formatting I figured out that formatting with

    <td>
      DATA
    </td>
    

    causes the white space to be interpreted as a part of the field title. By putting it all on a single line, the problem resolved.

Sign In or Register to comment.