This is a migrated thread and some comments may be shown as answers.

Excel Export - Date Formatting Based Upon Culture

2 Answers 437 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JosephB
Top achievements
Rank 1
JosephB asked on 27 May 2014, 06:14 PM
I have a Grid in which dates are always displayed in MM/dd/yyyy format.  However, when we export the grid to Excel, we want the date format to be culture-specific.  For example, a US-based user would see 5/27/2014 for today's date while a UK-based user would see 27/05/2014.

Is there a simple way to accomplish this?  Setting the Culture property of the Grid did not do the trick.  I eventually solved the problem by putting some code into the Grid's ExportCellFormatting event in which I convert the Cell.Text to a DateTime (from a string) and subsequently cast the DateTime to a string for the Culture that I retrieve from Request.UserLanguages.

Thanks in advance!

2 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 30 May 2014, 10:09 AM
Hi Joseph,

Thank you for contacting us.

Could you please let me know which export format you are using? I prepared a small sample where I used the HTML based on format which is the default one and the date is exported based on the culture. I attached the sample to thread so could you please give it a try and let me know how it differs from your real setup?

I am looking forward to your reply.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
trupti
Top achievements
Rank 1
answered on 14 Aug 2018, 01:27 PM

We need to convert the Cell.Text to a DateTime (from a string) and subsequently cast the DateTime to a string for the Culture we retrieve from Request.UserLanguages. but after this we need to set

cell.format ="\@"

so that this datetime would be exported as string to Excel(Xlsx) and would not converted again as per system setting of date format in Excel file 

Tags
Grid
Asked by
JosephB
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
trupti
Top achievements
Rank 1
Share this question
or