Date (YYYY-MM-DD) in table header not exported correctly to xlsx

Date (YYYY-MM-DD) in table header not exported correctly to xlsx

kolousekkolousek Posts: 3Questions: 1Answers: 0

Link to test case: https://live.datatables.net/ruhifuxo/1/edit

Description of problem: When you have a date in the table header, it gets converted to some integer when exporting to excel (in the example above 2025-04-03 turns into 45750). When you add a non-empty string to the date, it's fine, so i assume, that some autoformatting/autodetection goes wrong.
Export to csv works fine tho.
I've tried to mess with exportOptions.format.header, but to no avail so far.

Thanks for any advice!

Answers

  • kolousekkolousek Posts: 3Questions: 1Answers: 0
    {
            match: /^(19\d\d|[2-9]\d\d\d)\-(0\d|1[012])\-[0123][\d]$/,
            style: 67,
            fmt: function (d) {
                return Math.round(25569 + Date.parse(d) / (86400 * 1000));
            }
        } //Date yyyy-mm-dd
    

    looks like this filter is applied (from buttons.html4.js), but the style is not used?

  • allanallan Posts: 64,332Questions: 1Answers: 10,623 Site admin

    OOft. I think it is because the header is ISO8601 formatted in your example there. Compound styles are an absolute pita in XSLX files and I have it set to be bold styling for header cells, which removes the formatting for date cells.

    Thanks for letting me know about that. The would around at the moment would be to use a format that isn't ISO8601 (YYYY/MM/DD for example wouldn't match that regex).

    Allan

  • kolousekkolousek Posts: 3Questions: 1Answers: 0

    The easiest way - using slashes instead of dashes did not cross my mind, thanks a lot!

Sign In or Register to comment.