Hi,
This is not possible out of the box, but can be achieved manually by using the following method:
private void ApplyFormatting(Worksheet sheet, int fromRow, int toRow)
{
var rows = sheet.Cells.Where(cell => cell.Row >= fromRow && cell.Row <= toRow).GroupBy(cell => cell.Row);
foreach (var row in rows)
{
int rowIndex = row.Key;
bool met = false;
foreach (var cell in row)
{
if (cell.Value is double)
{
if ((double)cell.Value < 0)
{
met = true;
break;
}
}
}
if (met)
sheet.Rows[rowIndex].Style.Background = new MindFusion.Drawing.SolidBrush(Color.Red);
else
sheet.Rows[rowIndex].Style.Background = null;
}
}
The method inspects the cells in the specified rows and applies the appropriate background to the entire row. You can initially call this method for all rows in the worksheet. Then you can listen to the Worksheet.CellChanged event and call the method only for the affected row:
activeSheet.CellChanged += (s, e) =>
{
ApplyFormatting(e.Cell.Worksheet, e.Cell.Row, e.Cell.Row);
};
However, this event is not raised when the value of a cell is changed indirectly, for example, as a result of a formula reevaluation. If you have formulas in the worksheet, you may need to update all rows again.
Regards,
Meppy