Dates not formatted on Excel

I'm exporting my grid to Excel, but for some reason the format I use on dates is not applied to the Excel file. Here is a Stackblitz with the issue:


As you can see I'm using the format

{type: 'date', skeleton: 'short'}

for dates, but it is not applied when exporting to Excel.

I was given this example by Chat:


This one is working, but I just couldn't find what makes the difference in functionality. 

Another difference between both, is that in my Stackblitz the app stops working if I remove the "type" property from the column, meanwhile in yours you don't need it for the app to work. So there is definitely something differente in our code, but I haven't been able to spot it.

Can you tell me how to get the formatting working when exporting to Excel on the Stackblitz I provided?



3 Replies 1 reply marked as answer

TS Thiyagu Subramani Syncfusion Team June 4, 2020 04:16 AM UTC

Hi Ricardo, 

Thanks for contacting Syncfusion forum. 

In first stackblitz sample you have used TestDate field value type as string like ‘2044-06-01T00:00:00.000Z’ (ISO date string).  

By default in EJ2 Grid the date column values must be in date object then only format, filtering and sorting operation will be properly applied to the date column.  

In column API if you set type as date in column level then the string values will be converted to date object in source level and format will be properly applied to the date column. But if we export the excel, cell value as maintained as string instead of date object, So we have to change the required cell value as data value using excelQueryCellInfo event.  


 

Please refer to the below code and modified sample. 

excelQueryCellInfo(args): void { 
    if(args.column.field === 'TestDate'){ 
    args.data[args.column.field] = new Date(args.data[args.column.field]); 
    args.value = args.data[args.column.field]; 
  } 




 

But in your reported second sample, you are used required OrderDate field type as date object in dataSource. So its works fine and no need to define type as date in column level. Please refer to the below image and sample. 

 


Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S. 


Marked as answer

RS Ricardo Salas June 4, 2020 04:06 PM UTC

Thanks a lot for the explanation, it is working as expected now.


TS Thiyagu Subramani Syncfusion Team June 5, 2020 04:11 AM UTC

Hi Ricardo,  

Thanks for the update.  

We are happy to hear that your issue is resolved.  

Please get back to us if you need further assistance.  

Regards,  
Thiyagu S.  


Loader.
Up arrow icon