We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Export GridDataBoundGrid to Excel preserving formats and colors

Thread ID:

Created:

Updated:

Platform:

Replies:

61961 Jun 5,2007 12:54 PM UTC Jun 6,2007 09:13 AM UTC WinForms 2
loading
Tags: GridControl
Edijs
Asked On June 5, 2007 12:54 PM UTC

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

haneefm [Syncfusion]
Replied On 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

Edijs
Replied On June 6, 2007 09:13 AM UTC

Thanks, Haneef.

It helped.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;