Hello All,
I am exporting a XamDataGrid to Excel. A lot of the cells have a boolean value in them. For these cells, rather than exporting the strings "TRUE" and "FALSE", I want to leave the cell blank if the value is false, and I want to color it yellow if the value is true. Below is my attempt to do this. The cells with a value of true are being colored black, even though I explicitly stated "Yellow". How can I fix this?
Thanks,Dave
private void HandleCellExporting(object sender, CellExportingEventArgs e){ // Non-routed event e.Cancel = true;
int row = e.CurrentRowIndex; int col = e.CurrentColumnIndex;
string cellContent = string.Empty;
if (e.Value is string) cellContent = (string)e.Value; else if (e.Value is bool) { if ((bool)e.Value) { e.Workbook.Worksheets[e.CurrentWorksheet.Index].Rows[row].Cells[col]. CellFormat.FillPattern = FillPatternStyle.Solid;
e.Workbook.Worksheets[e.CurrentWorksheet.Index].Rows[row].Cells[col]. CellFormat.FillPatternBackgroundColor = Color.FromName("Yellow"); } }
e.Workbook.Worksheets[e.CurrentWorksheet.Index].Rows[row].Cells[col].Value = cellContent;}
The Solid FillPatternStyle has all of its foreground pixels turned "on" and so they cover-up whatever background fill color is used.
What you can do is set the FillPatternForegroundColor to Yellow instead of FillPatternBackgroundColor.