我设置了条件格式,它将根据字符串列表中的值突出显示单元格。效果很好,但我需要突出显示行中的某个范围,而不仅仅是一个单元格。
我需要每行突出显示xlsNewSheet.Range [xlsNewSheet.Cells [x,1],xlsNewSheet.Cells [x,8]]的范围,其中某些单元格等于字符串。
Excel.Range formatRange6 = (Excel.Range)xlsNewSheet.Range[xlsNewSheet.Cells[2, 2], xlsNewSheet.Cells[rw, 2]].Cells;
for (var k = 0; k < DesignIDs.Count; k++)
{
if (k % 2 == 0)
{
Excel.FormatCondition format2 = (Excel.FormatCondition)formatRange6.FormatConditions.Add(Excel.XlFormatConditionType.xlTextString, Type.Missing, Type.Missing, Type.Missing, "" + DesignIDs[k] + "", Excel.XlFormatConditionOperator.xlEqual, Type.Missing, Type.Missing);
format2.Interior.Color = 0x8FBC8F;
Marshal.ReleaseComObject(format2);
format2 = null;
}
else
{
Excel.FormatCondition format2 = (Excel.FormatCondition)formatRange6.FormatConditions.Add(Excel.XlFormatConditionType.xlTextString, Type.Missing, Type.Missing, Type.Missing, "" + DesignIDs[k] + "", Excel.XlFormatConditionOperator.xlEqual, Type.Missing, Type.Missing);
format2.Interior.Color = 0x5858C1;
Marshal.ReleaseComObject(format2);
format2 = null;
}
}
我尝试使用一个单元格的颜色来设置行中其余单元格的颜色,但是看来我无法根据单元格的颜色来声明。
for (var n = 1; n < formatRange6.Cells.Count; n++)
{
Excel.Range formantRange8 = (Excel.Range)xlsNewSheet.Range[xlsNewSheet.Cells[n, 1], xlsNewSheet.Cells[n, 8]].Cells;
if (xlsNewSheet.Cells[n][2].Interior.Color == "certain color")
formantRange8.Interior.Color = 0x8FBC8F;
}