繁体   English   中英

如何根据一个单元格的值突出显示一行中的单元格?

[英]How to highlight a range of cells in a row based the value of one cell?

我有一个条件格式设置,它将根据字符串列表中的值突出显示一个单元格。 这工作正常,但我需要突出显示行内的某个范围,而不仅仅是一个单元格。

我需要在某一单元格等于字符串的每一行中突出显示的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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM