c# application excel vsto 条件格式
c# application excel vsto conditional formatting
我有一个 VSTO c# 应用程序,我正在尝试应用条件格式,所以当 V 列中的值设置为“否”时,整行都变成灰色。 headercount 变量是我的最后一列编号
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;
我有一个 VSTO c# 应用程序,我正在尝试应用条件格式,所以当 V 列中的值设置为“否”时,整行都变成灰色。 headercount 变量是我的最后一列编号
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;