Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
Exporting Cells to Excel with Fill Color
posted

I'm trying to add a background to a cell that I'm exporting from a XamDataGrid to Excel.

In the CellExporting event, I'm conditionally applying a formula, then setting the fill.

This works fine for cells without a formula, however, the color is not showing on cells that contain formulas. What do I need to change?

private void grid_CellExporting (object sender, CellExportingEventArgs e)
{
var cell = e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex];

...

if (hasFormula)
{
cell.ApplyFormula(formula);
}
...

e.FormatSettings.FillPatternBackgroundColor = Color.Yellow;
e.FormatSettings.FillPatternForegroundColor = Color.Yellow;
e.FormatSettings.FillPattern = FillPatternStyle.Solid;
}