Export GridDataBoundGrid to Excel preserving formats and colors

Hi!

I am trying to export GridDataBoundGrid data to Excel and I am facing two problems when I look at the exported excel file:

1) Cell back color is not exported.
2) DateTime columns values are not exported in the same format, they appear on the grid.

I have also attached a code sample.

Regards,
Edijs

GridDataBoundToExcel.zip

2 Replies

HA haneefm Syncfusion Team June 5, 2007 04:01 PM UTC

Hi Edijs,

The reason is that you are using the PrepareViewStyleinfo event. PrepareviewStyleInfo event does not store any styleInfo properties in a grid. It just set the visual apperence of the grid. GridToExcel method exports the stored style into excel. It depends on the data stored in a grid. If you want to set as well as store the style of the cell, then you can handle the QueryCellInfo event of the grid. Here is a code snippet

gridDataBoundGrid1.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo);

void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex == 1)
e.Style.BackColor = Color.LightBlue;
else if (e.ColIndex == 2)
e.Style.Format = "MM/dd/yyyy";
}

Best regards,
Haneef


ED Edijs June 6, 2007 09:13 AM UTC

Thanks, Haneef.

It helped.

Loader.
Up arrow icon