簡體   English   中英

C#Excel格式條件

[英]C# excel format Condition

我正在嘗試在C#中使用Excel條件格式。 下面是代碼:

Excel.Range rangeFormat = ws.get_Range("F1", "F1");
Excel.FormatConditions fcs = range.FormatConditions;
Excel.FormatCondition fc = (Excel.FormatCondition)fcs.Add
    (Excel.XlFormatConditionType.xlExpression, Type.Missing, "=IF($F$1) >= 10", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Excel.Interior interior = fc.Interior;
interior.Color = ColorTranslator.ToOle(Color.Red);
interior = null;
fc = null;
fcs = null;

但是,我得到了ParameterCountException但是我確定已經給了它正確數量的參數。

MSDN建議Excel.FormatCondition.Add最多使用4個參數

FormatCondition Add(
    [In] XlFormatConditionType Type, 
    [In, Optional] object Operator, 
    [In, Optional] object Formula1, 
    [In, Optional] object Formula2
);

您可以嘗試將其鍵入為:

Excel.FormatCondition fc = (Excel.FormatCondition)fcs.Add(
    Type: Excel.XlFormatConditionType.xlExpression,
    Formula1: "=IF($F$1) >= 10"
);

盡管您使用的公式看起來也可能不正確。 我認為您probalby想要=$F$1 >= 10 ,盡管在這種情況下,您還應該可以使用:

Excel.FormatCondition fc = (Excel.FormatCondition)fcs.Add(
    Type: Excel.XlFormatConditionType.xlExpression,
    Operator: Excel.XlFormatConditionOperator.xlGreaterEqual
    Formula1: "10"
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM