escaping moment.js characters in exported excel filename

escaping moment.js characters in exported excel filename

crush123crush123 Posts: 417Questions: 126Answers: 18
edited January 2017 in DataTables

i am exporting a table to excel using html5 button, and setting the title of the export.

what i would like to do is append the date and time to the file name, which kinda works, except the characters as date separators are not working.

i checked the syntax on moment.js, but no joy,

this is my code

{
            extend: 'excelHtml5',
            exportOptions: {
                columns: [ 1, 2, 3, 4, 5, 7, 8, 10]
            },
    title: 'Membership_Renewals '+ moment().format('DD[/]MM[/]YYYY h[:]mm a')
        },

and i get Membership_Renewals 11012017 932 am

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    You can't have a : in a windows file name, so it get's stripped automatically. There is no way around that that I'm aware of. You could obviously change the Buttons code to not strip the characters, but I think you'd get an error from your host OS.

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    okay, thanks for that - its easy to replace the colon with a dot.

    any idea why the slash doesn;t work ?

    i can get around it by formatting differently, but would be nice to know.

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Answer ✓

    Its a Unix directory separator. Not sure what it means in Windows...

    Allan

This discussion has been closed.