Home » excel » C# to Excel – Custom formatting?

C# to Excel – Custom formatting?

Posted by: admin May 14, 2020 Leave a comment


Is there a way to apply custom formatting if value in cell is less then 0 set color to be RED.

I know how to do this by setting color for individual cell, but what I have is 8 reports with lots of cells and I just want to apply this rule on whole sheet, so I don’t have to do it for each cell.

Thanks in advance.

How to&Answers:

There is no way to do it in interop lower than 12 version.

I have changed version of interop.excel to 14 for Excel 2010 and its working with

FormatCondition f = (FormatCondition)r.FormatConditions.Add(XlFormatConditionType.xlCellValue,
                                                       XlFormatConditionOperator.xlLess, 0, misValue, misValue,
                                                       misValue, misValue, misValue);
            f.Font.Color = ColorTranslator.ToOle(Color.Red);

FormatCondition property