How do I test for a cell's font color?


#1

I need to format cells based on the font color within the cell.

For example:

if a cell’s font color is black, apply style1.
if a cell’s font color is blue, apply style2.



etc.

How would I do this?


#2

if(cell.Style.Font.Color.ToArgb() == Color.Black.ToArgb())
cell.Style = style1;


But I don’t suggest to write your program in this way for each cell will create a Style object. It will consume huge amount of memory if there are many cells in a worksheet.

Could you try to set the style based on other condition?


#3

Thanks, I’ll try this.

I need to test for font color because I’m reformatting existing reports. I’m only using 2 style objects for this anyway, which will be used across all worksheets within the workbook.