如果值與另一列中的值不同,我需要將顏色應用於單元格的文本。最好的方法是什麼?我能想到的方式非常昂貴。使用C#在Excel中進行條件格式化#
for (int i = 0; i < ColumnARange.Cells.Count; i++)
{
if (ColumnARange.Cells[i, 1] != ColumnBRange.Cells[i, 1])
{
Range currCell = ColumnBRange.Cells[i, 1];
currCell.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
}
}
嘗試條件格式如下,但徒勞無功。
FormatCondition cond = ColumnBRange.FormatConditions.Add(XlFormatConditionType.xlCellValue, XlFormatConditionOperator.xlNotEqual, ColumnARange);
cond.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
我使用VSTO,C#
條件格式? – mellamokb 2012-04-20 04:24:19
是的。需要通過與其他列的值進行比較來將顏色應用於單元格文本。但是如果我像我的代碼中提到的那樣遍歷,考慮具有更多行和列的大數據將會非常昂貴。 – Cannon 2012-04-20 04:27:02