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

RadGridView to Excel

4 Answers 269 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bajik Evgen
Top achievements
Rank 1
Bajik Evgen asked on 29 Jul 2009, 04:57 AM
Q2 2009
Visual Studio 2008

When exporting to Excel I have not properly displayed, a text field in DataGrid, which is looks like "1/5" are displayed in Excel as "39818" and the field DataTime original meaning "28.07.2009 11:59:22" are displayed in Excel as a "40022.62126".

RadGridViewExcelExporter exporter = new RadGridViewExcelExporter();
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
     string path = saveFileDialog.FileName;
     exporter.Export(this.RGridView, path, "List 1");
}

How do I make that data would be displayed when exporting to Excel correctly?

4 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 31 Jul 2009, 10:31 AM
Hello Bajik Evgen,

Thank you for writing. You can specify the exported format by using the grid column properties ExcelExportType and ExcelExportFormatString. Please consider the following code snippet:
 
this.radGridView1.Columns["Date"].ExcelExportType = DisplayFormatType.Custom;  
this.radGridView1.Columns["Date"].ExcelExportFormatString = "dddd, dd.MM.yyyy"

You can find more details on exporting in our product documentation. Do not hesitate to contact me again if you have other questions.

Greetings,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
MiroslavStantic
Top achievements
Rank 1
Iron
answered on 09 Jun 2010, 11:29 AM
Excel document still contains only a number, instead of a well formatted date value. I tried using ShortDate, and also this Custom format.
I am using the RadGrid with AutoGenerateColumns = True.
In DataBindingComplete event I go through all the columns like this:

        For Each col As GridViewDataColumn In GRD.Columns 
            If TypeOf col Is GridViewDateTimeColumn Then 
                CType(col, GridViewDateTimeColumn).FormatString = "{0:dd-MMM-yyyy}" 
                col.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter 
                col.ExcelExportType = DisplayFormatType.Custom 
                col.ExcelExportFormatString = "dd-MMM-yyyy"
            End If 
        Next col
0
Martin Vasilev
Telerik team
answered on 15 Jun 2010, 07:43 AM
Hello Miroslav Stantic,

I have already answered your question in the support ticket, which you created about the same issue. However I am posting the answer here as well to make it public for the community.

Actually, only ExporToExcelML class supports Excel formatting and takes into consideration ExcelExportType and ExcelExportFormatString settings. Please, give it a try and let me know if you have any additional questions.

Best wishes,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
MiroslavStantic
Top achievements
Rank 1
Iron
answered on 15 Jun 2010, 09:04 AM
Yes, it works very good, thanks.
Tags
GridView
Asked by
Bajik Evgen
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
MiroslavStantic
Top achievements
Rank 1
Iron
Share this question
or