C#到Excel – 自定义格式?

是否有一种方法来应用自定义格式,如果单元格中的值小于0,则将颜色设置为红色。

我知道如何通过为单个单元格设置颜色来实现这一点,但我所拥有的是8个有很多单元格的报表,我只是想在整张表格上应用这个规则,所以我不必为每个单元格做这个工作。

提前致谢。

在12以下的版本中,没有办法做到这一点。

我为Excel 2010及其工作版本将interop.excel的版本更改为14

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

FormatCondition属性