2017-04-01 45 views

回答

1

這將取決於哪些單元格的內容和驗證的操作員的設置:

http://epplus.codeplex.com/SourceControl/latest#EPPlus/DataValidation/ExcelDataValidationOperator.cs

/// <summary> 
/// Operator for comparison between Formula and Formula2 in a validation. 
/// </summary> 
public enum ExcelDataValidationOperator 
{ 
    any, 
    equal, 
    notEqual, 
    lessThan, 
    lessThanOrEqual, 
    greaterThan, 
    greaterThanOrEqual, 
    between, 
    notBetween 
} 

ExcelDataValidationDateTime(最終)從ExcelDataValidationWithFormula<IExcelDataValidationFormulaDateTime>其中包含Validate()的實行得出:

http://epplus.codeplex.com/SourceControl/latest#EPPlus/DataValidation/ExcelDataValidationWithFormula.cs

public override void Validate() 
{ 
    base.Validate(); 
    if (Operator == ExcelDataValidationOperator.between || Operator == ExcelDataValidationOperator.notBetween) 
    { 
     if (string.IsNullOrEmpty(Formula2Internal)) 
     { 
      throw new InvalidOperationException("Validation of " + Address.Address + " failed: Formula2 must be set if operator is 'between' or 'notBetween'"); 
     } 
    } 
} 

因此,這將拋出異常(無效)時,驗證操作是要麼ExcelDataValidationOperator.betweenExcelDataValidationOperator.notBetweenForumla2未設置(不與主Formula混淆)。換句話說,當您使用需要比較兩個值/公式進行比較但僅設置一個的操作時,它認爲驗證器無效。

+0

謝謝,那麼它不會驗證單元格內容嗎?內容驗證是手動完成的? –

+0

@AlirezaAhmadiRad在設計時,不,該函數不驗證驗證器本身的定義。當用戶打開excel文件並添加內容時,驗證會檢查其輸入。至於驗證代碼中的單元格值,我不相信EPPlus具有我認爲的能力,因爲他們希望開發人員能夠處理它。 – Ernie