2017-04-01 129 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