Export to Excel from GDBG, problem with date types...

Hi,
I am using GDBG version 4.4.xxx
One of my columns in the grid is of type Date

I am exporting the rows from the grid to excel using GridExcelConvertorControl

GridDataBoundGrid exportGrid = new GridDataBoundGrid();
exportGrid.DataSource = dt //my data table;


GridExcelConverterControl gecc = new GridExcelConverterControl();
gecc.GridToExcel(exportGrid.Model, sFileName, ConverterOptions.RowHeaders | ConverterOptions.Visible);

For most part it works ok. However the Date type is getting exported into some numbers.

Looks like the Excel column format that is suppose to show date is not getting set correctly.

Is there a way programattically, such that I can specify the format for each cell programatically prior to export?

4 Replies

J. J.Nagarajan Syncfusion Team September 1, 2007 01:34 AM UTC

Hi Pratima,

If you set the GridStyleInfo.StyleInfo.Format property for your DateTime column, then the export should work ok. Here is the sample we ship created to show this idea.

http://www.syncfusion.com/Support/user/uploads/GDBGExport_2b9d6b4f.zip

Let us know if this is not what you wanted.

Regards,
Nagaraj


PR Pratima September 1, 2007 02:55 AM UTC

My Grid's datasource is a SQL DataTable which already has the field of type DateTime

Which means grid is automatically creating a column of type DateTime isn't it?

Do I need to explicitly reset the exact same format again?

Thanks,
Pratima


PR Pratima September 1, 2007 03:11 AM UTC

OK, so looks like the problem is how I set the format.

For example.

1) If I set the format = "mm/dd/yyyy"

Grid displays it properly
Exported file shows it properly

2) If I set the format = "d" ( which is syncfusion's format for short date )

Grid Displays it properly
Exported file DOES NOT show it correctly. I see the 39325.80 in the excel spreadsheet

Looks like a bug in Grid convertor which doesn't recognize the coded format from GDBG




RA Rajagopal Syncfusion Team September 3, 2007 11:29 PM UTC

Hi Pratima,

Thanks for your patience.

We are not able to see this issue in the latest version 5.1.x.x. This has been internally fixed in the latest version of Essential Studio 5.1.

As a workaround, you can handle the QueryCellInfo event and apply the FormattedText to the datetime cells in grid. Please refer the below sample that shows this working fine.

http://www.syncfusion.com/Support/user/uploads/GDBG_ExcelExport_6d5da8a4.zip

Let me know if you have any other questions.

Have a nice time.
Regards,
Rajagopal

Loader.
Up arrow icon