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

[Solved] RadGrid Q3 2009 - Export To Excel Date column converts to String

3 Answers 300 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Divyesh
Top achievements
Rank 1
Divyesh asked on 08 Dec 2009, 01:01 PM
Hi,

I am exporting RadGrid data to excel where I have couple of columns of type date. ExportToExcel() converts those date columns to string type. The date columns are specified as below in my RadGrids.

<telerik:GridDateTimeColumn     FilterControlWidth="120" 
                                                    DataField="NearestEndDate" 
                                                    DataType="System.DateTime"     
                                                    EditFormHeaderTextFormat="{0:MMM dd, yyyy}"
                                                    HeaderText="Next Subscription Expires" 
                                                    UniqueName="columnNextExpiryDate" 
                                                    SortExpression="NearestEndDate" 
                                                    DataFormatString="{0:MMM dd, yyyy}">
        <HeaderStyle Width="140px" />
        <ItemStyle Width="140px" />
</telerik:GridDateTimeColumn>

Any Idea what is the best way to set the format so that when I export this grid to excel the date column format stays same but the type of column should be date.

Regards
Div

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Dec 2009, 03:27 PM
Hello Div,

Set the date format in ExcelExportCellFormatting event this way:

protected void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e)
{
    if (e.FormattedColumn.UniqueName == "ColumnName")
    {
        e.Cell.Style["mso-number-format"] = @"mmm\_dd\,\_yyyy";
    }
}

I hope this helps.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Divyesh
Top achievements
Rank 1
answered on 08 Dec 2009, 03:44 PM
Hi Daniel,

Thank you for your reply.
It does not work. meaning...

If I try to sort the resultant spreadsheet on that column I cant sort it as date. It treats that column as character type. That is my problem more than the display formating of a column(cell). I need to specify the type of cell entery instead of formatting type.

Regards
Div
0
Daniel
Telerik team
answered on 10 Dec 2009, 06:54 PM
Hello Div,

Please download the attached sample files (video and demo project) and let me know if you need more information.

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Divyesh
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Divyesh
Top achievements
Rank 1
Share this question
or