我有一个 VSTO c# 应用程序,我正在尝试应用条件格式,因此当第 V 列中的值设置为"否"时,将整行设置为灰色。 标题计数变量是我的最后一个列号
Microsoft.Office.Interop.Excel.FormatCondition format7 = (Microsoft.Office.Interop.Excel.FormatCondition)(uiWorksheet.get_Range("B7:Z" + headercount,
Type.Missing).FormatConditions.Add(Microsoft.Office.Interop.Excel.XlFormatConditionType.xlExpression, Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlEqual,
"V=No", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));
format7.Interior.Color = true;
我尝试了以下内容,但它不起作用 - 有什么想法吗?
我能够使用 Excel 的 INDIRECT
函数和由 Application.SheetChange
事件触发的条件格式来使其工作。请注意,公式的内部引号需要转义。
Microsoft.Office.Interop.Excel.FormatCondition format7 = (Microsoft.Office.Interop.Excel.FormatCondition)(uiWorksheet.get_Range("B7:Z" + headercount,
Type.Missing).FormatConditions.Add(Microsoft.Office.Interop.Excel.XlFormatConditionType.xlExpression, Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlEqual,
"=INDIRECT("V"&ROW())="No"", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));
format7.Interior.Color = System.Drawing.Color.Gray;