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

ExportToXlsx: DateTime Format

1 Answer 269 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alessandro Strazzari
Top achievements
Rank 1
Alessandro Strazzari asked on 19 Mar 2020, 05:58 PM

Hello,

I have some problem with Export to Excel for DateTime Format Columns.

Set Column Format:

(this.myGrid.Columns["JPr_MinStart"] as GridViewDataColumn).DataFormatString = "dd/MM/yyyy hh:mm";

 

On ElementExportingToDocument:

01.private void myGrid_ElementExportingToDocument(object sender, GridViewElementExportingToDocumentEventArgs e)
02.{
03.    if (e.Element == ExportElement.Cell)
04.    {
05.        var cellExportingArgs = e as GridViewCellExportingEventArgs;
06.        if (
07.            (cellExportingArgs.Column as GridViewDataColumn).UniqueName == "JPr_MinStart"
08.        )
09.        {
10.            (cellExportingArgs.Column as GridViewDataColumn).DataFormatString = string.Empty;
11.            var parameters = cellExportingArgs.VisualParameters as GridViewDocumentVisualExportParameters;
12.            parameters.Style = new CellSelectionStyle()
13.            {
14.                Format = new CellValueFormat("dd/MM/yyyy hh:mm")
15.            };
16.        }
17.    }
18.}

On ElementExportedToDocument

private void myGrid_ElementExportedToDocument(object sender, GridViewElementExportedToDocumentEventArgs e)
 {
         if (e.Element == ExportElement.Table)
{
      (this.myGrid.Columns["JPr_MinStart"] as GridViewDataColumn).DataFormatString = "dd/MM/yyyy hh:mm";
}
 }

 

If I set DateFormatString, the export to Excel is wrong. It export the value as String and Excel cannot recognize the DateTime column.

If i remove DateFormatString on Exporting and on Exported I set the DateFormat string, the Excel is right but the first line no!

 

I think that is a bug? My WPF version is: 2018.1.220.40

Thank you very much

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 24 Mar 2020, 01:44 PM

Hello Alessandro,

This behavior is addressed in the Export DateTime Value article. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
GridView
Asked by
Alessandro Strazzari
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or