简体   繁体   English

c# 应用 excel vsto 条件格式

[英]c# application excel vsto conditional formatting

I have a VSTO c# application and I am trying to apply conditional formatting so when the value in Column V is set to No make the whole row grey.我有一个 VSTO c# 应用程序,我正在尝试应用条件格式,因此当第 V 列中的值设置为否时,使整行变为灰色。 headercount variable is my last column number 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;

I tried the below but it doesnt work - any ideas?我尝试了以下方法,但它不起作用 - 有什么想法吗?

I was able to get this to work using Excel's INDIRECT function with the conditional formatting triggered by the Application.SheetChange event.我能够使用 Excel 的INDIRECT function 以及由Application.SheetChange事件触发的条件格式来使其工作。 Please note that the internal quotation marks for the formula need to be escaped.请注意,公式的内部引号需要转义。

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;

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

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