RadGridView Export to Excel: Formatting Date whilst Retaining Local Style

562 views Asked by At

I'm attempting to export a row which is present in a Telerik RadGridView to Excel. This row represents a date/time.

The code which formats the data in this row is as follows:

if (DateTime.TryParse(value.ToString(), out dateTimeValue))
{
    cell.SetValue(dateTimeValue);
    return;
}

The problem with this is, if the value is midnight (which is quite common in the app I'm working on) it doesn't show the time. This is an Excel feature, but looks odd (and bad on us) to the end user.

You can get around this by enforcing a format on the date as follows:

if (DateTime.TryParse(value.ToString(), out dateTimeValue))
{
    cell.SetValue(dateTimeValue);
    cell.SetFormat(new CellValueFormat("MM/dd/yyyy hh:mm"));
    return;
}

But the problem with this is the date format is US based. This app is used worldwide and so needs to reflect the local culture.

Do you know how to apply such a format when exporting from a RadGridView, whilst respecting the local culture settings?

Thanks in advance.

0

There are 0 answers