hhurz / tableExport.jquery.plugin

jQuery plugin to export a html table to JSON, XML, CSV, TSV, TXT, SQL, Word, Excel, PNG and PDF
MIT License
984 stars 714 forks source link

Date format issue #302

Closed Ranjith080216 closed 4 years ago

Ranjith080216 commented 4 years ago

In the front end my dates are like this 05/05/2020 & 05/04/2020 but when i export to excel the dates are showing as 5/4/2020 and 4/4/2020.

My date Format: mm/dd/yyyy I am in GMT-4 time zone.

One more example: In Front end | In Excel 05/10/2019 | 10/4/2019 05/09/2019 | 9/4/2019 02/04/2019 | 4/1/2019

Also noticed this when ever i have dd greater than 12 i think the excel is showing the correct date. In Front End | In Excel 04/26/2019 | 04/26/2019 05/29/2019 | 05/29/2019

Can you please suggest me a solution for this. IMG_9812

Ranjith080216 commented 4 years ago

My issue got fixed by adding date: {html: 'yyyy-mm-dd'} to the tableExport function.

Example: $('#id').tableExport({ type: 'xlsx', date: {html: 'yyyy-mm-dd'} })

hhurz commented 4 years ago

@Ranjith080216 Hi, thanks for sharing your way how you solved that issue. I just want to leave a comment to your workaround: Your date format is mm/dd/yyyy. By setting the tableExport option date: {html: 'yyyy-mm-dd'} the plugins date parser is unable to detect cells that contain dates and treats it as text. Excel presents such cells as text also, but not as date formated cells. If you don't care about loosing the date property in excel, your solution is fine as it is. But if you want to preserve dates as dates in excel I think the following tebleExport settings should work:

$('#id').tableExport({
      type: 'excel',
      date: {html: 'mm/dd/yyyy'},
      mso: {fileFormat: 'xlsx',
            xslx: {formatId: {date: 'mm/dd/yyyy'}},
    });

FYI: There was a bug in parsing dates before version v10.1.14 (see #288) I mention this just to get sure that you are using a newer version than that.