How can i give styles in data table excel export?

How can i give styles in data table excel export?

prasanna_pprasanna_p Posts: 1Questions: 0Answers: 0

I am trying to write the styles for data table excel export but,I am not finding any solution to get it done.Is there any way to write styling in excel export data including excel headers and body data.

Replies

  • allanallan Posts: 63,201Questions: 1Answers: 10,414 Site admin

    There is no option for that at the moment. If you search this forum you'll find a number of similar posts asking for this feature.

    It is something that I hope to introduce into the Excel export soon.

    Allan

  • rherringrherring Posts: 5Questions: 0Answers: 0

    Not to beat a dead horse, but is there any progress on being able apply styles to the exported XLSX file format?

  • allanallan Posts: 63,201Questions: 1Answers: 10,414 Site admin

    Yes. See the documentation in the excelHtml5 button reference. The files are created as XML nodes so you can customise as you wish. There are 50 basic built in styles and you can add more if you want (and you know how to add styles in XSLX!).

    Allan

  • rherringrherring Posts: 5Questions: 0Answers: 0

    This is fantastic news. Thanks for the quick response.

    The documentation says to use XML for the styles. I'm very familiar with XML, but is there a specific layout that DataTables is looking for? Do you have an example of what the XML file would look like?

  • allanallan Posts: 63,201Questions: 1Answers: 10,414 Site admin

    I'm very familiar with XML, but is there a specific layout that DataTables is looking for?

    DataTables isn't looking for anything - it is Excel that you need to create the XSLX file for.

    The documentation for the excelHtml5 button links to the MSDN documentation for the spreadsheet specification.

    Do you have an example of what the XML file would look like?

    Use one of the Buttons examples to create an xslx file, rename the extension to be zip and unzip it. You'll be able to see the file structure and XML structure Excel uses.

    Also have a look at some of the Buttons examples which show how to use the built in styles.

    Allan

  • rherringrherring Posts: 5Questions: 0Answers: 0

    Sweet thanks. Now it's just trial and error until I can figure out how to get all my styles dynamically put into the documents I'm creating.

  • rherringrherring Posts: 5Questions: 0Answers: 0

    Thank you so much for the help you've provided, I think I have one last question.

    To make all of column "C" have normal text, white background, and a thin border, I'm using this code:

    $('row c[r^="C"]', sheet).attr( 's', '25' );

    But I have a few custom colors that I'm needing to use, like #f2dcdb. Is is possible to use a custom background, and if so, how?

    Thanks,
    Rob

  • allanallan Posts: 63,201Questions: 1Answers: 10,414 Site admin

    It is, but you would need to create a custom style. This is where Buttons defines its built in styles. You could potentially use that as a guide to create your custom style. Because of how the styling works, you would need a new style that defines the font, border and background colour. Its not as straight forward as CSS sadly...

    Allan

  • rherringrherring Posts: 5Questions: 0Answers: 0

    This was PERFECT!!! I was able to get ALL of my style from my website into the excel document I'm exporting.

    Thanks so much for all the help.

  • allanallan Posts: 63,201Questions: 1Answers: 10,414 Site admin

    Awesome - thanks for letting me know. That's the first feedback that I've had that this feature is actively being used :smile: .

    Allan

This discussion has been closed.