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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Unable to show cell backcolor of the GridControl while exporting to excel

Thread ID:

Created:

Updated:

Platform:

Replies:

95296 Jun 30,2010 10:56 AM UTC Jul 2,2010 11:57 AM UTC WinForms 4
loading
Tags: GridControl
ramnadh
Asked On June 30, 2010 10:56 AM UTC

We are using syncfusion Essential Studio 7.1.0.30 Grid control for showing the data in the tabular form.

We have a screen where we will have some cells in the grid shown with backcolor and fontcolor dynamically based on the conditions.

When we are trying to export the grid data to excel, we are unable to export the cell backcolors and fontcolors to the excel sheet.

We have tried using the Excel ConditionalFormats, but not successful.

IConditionalFormats cond = e.ExcelCell.ConditionalFormats;
IConditionalFormat cond1 = cond.AddCondition();
cond1.FirstFormula = "0";
cond1.SecondFormula = "0";
cond1.Operator = ExcelComparisonOperator.Equal;
cond1.FormatType = ExcelCFType.CellValue;
cond1.BackColorRGB = Color.FromArgb(e.GridCell.BackColor.R, e.GridCell.BackColor.G, e.GridCell.BackColor.B);
e.ExcelCell.Value = text;

With the above code we see one of the color (yellow) is getting shown, but not the other RGB colors like Red, Green are not showing up.

Could anyone help us in defining the correct API for exporting the colors into the excel from the syncfusion GridControl

Jisha Joy [Syncfusion]
Replied On July 1, 2010 12:09 PM UTC

Hi Ramanadh,

Thank you for using Syncfusion products.

You could use GridExcelConverterControl class to export the grid contents along with styles to Excel sheet. See the code:

Syncfusion.GridExcelConverter.GridExcelConverterControl gecc = new Syncfusion.GridExcelConverter.GridExcelConverterControl();
gecc.GridToExcel(this.gridControl1.Model, FileName);

Sample can be accessed from the browser sample.


..\\Windows\Grid.Windows\Samples\2.0\Export\GC XLS Export Demo\cs

Regards,
Jisha

ramnadh
Replied On July 2, 2010 07:22 AM UTC

Hi Joy,
Appreciate your help in resolving the issue.
We are using the same GridExcelConverterControl.GridToExcel for exporting the grid to excel, but the problem we had is that we have customized the exporting the excel by registering the event QueryImportExportCellInfo and overriding the values for the cell types DataTypeCustomProperty.CellDataType.String, DataTypeCustomProperty.CellDataType.Date and DataTypeCustomProperty.CellDataType.DateTime

Example:
private void gridConverter_QueryImportExportCellInfo(object sender, GridImportExportCellInfoEventArgs e)
{
if (e.Action == Syncfusion.GridExcelConverter.GridConverterAction.Export)
{
GridDrawCellDisplayTextEventArgs e_ = new GridDrawCellDisplayTextEventArgs (null, e.GridCell.Text, Rectangle.Empty, e.GridCell);

OnDrawCellDisplayText (e_);

string text = (e_.DisplayText != null)? e_.DisplayText:e.GridCell.Text;

DataTypeCustomProperty dtcp = new DataTypeCustomProperty (e.GridCell);

switch ((dtcp.HasDataType)? dtcp.DataType:DataTypeCustomProperty.CellDataType.Undefined)
{
case DataTypeCustomProperty.CellDataType.String: e.ExcelCell.Value = text;
DataTypeCustomProperty.CellDataType.Date: e.ExcelCell.Value = /*Modifying format based on configuration*/;
default:
e.ExcelCell.Value = text;
}
e.Handled = true;

The problem is we when we register the event and overriding, we are formatting the display text, but not the formats.

To achieve formatting to the ExcelCell object, could you provide us an example or a reference, which will be helpful to us.

Thanks

ramnadh
Replied On July 2, 2010 10:27 AM UTC

Hi joy,

I think we are able to solve the issue by setting the e.ExcelCell.CellStyle properties.

e.ExcelCell.CellStyle.Color = e.GridCell.BackColor;
e.ExcelCell.CellStyle.Font.RGBColor = e.GridCell.TextColor;
e.ExcelCell.BorderAround(ExcelLineStyle.Thin, Color.Black);

We have set the background color, font color and border color.

Do you think this paradigm is correct? or do you suggest any other way to export the colors.

Thanks

Jisha Joy [Syncfusion]
Replied On July 2, 2010 11:57 AM UTC

Hi Ramanadh,

Glad to know that issue got resolved. Thank you for your update.

Regards,
Jisha

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

;