public class DataValidationEvaluator
extends java.lang.Object
For performance reasons, this class keeps a cache of all previously retrieved DataValidation
instances. Be sure to call clearAllCachedValues()
if any workbook validation definitions are added, modified, or deleted.
Changing cell values should be fine, as long as the corresponding WorkbookEvaluator.clearAllCachedResultValues()
is called as well.
Modifier and Type | Class and Description |
---|---|
static class |
DataValidationEvaluator.DataValidationContext
This class organizes and encapsulates all the pieces of information related to a single data validation configuration for a single cell.
(此类组织和封装与单个单元格的单个数据验证配置相关的所有信息。)
|
static class |
DataValidationEvaluator.OperatorEnum
Not calling it OperatorType to avoid confusion for now with DataValidationConstraint.OperatorType.
(暂时不将其称为 OperatorType 以避免与 DataValidationConstraint.OperatorType 混淆。)
|
static class |
DataValidationEvaluator.ValidationEnum
Not calling it ValidationType to avoid confusion for now with DataValidationConstraint.ValidationType.
(暂时不将其称为 ValidationType 以避免与 DataValidationConstraint.ValidationType 混淆。)
|
Constructor and Description |
---|
DataValidationEvaluator(Workbook wb, WorkbookEvaluatorProvider provider)
Use the same formula evaluation context used for other operations, so cell value changes are automatically noticed
|
Modifier and Type | Method and Description |
---|---|
void |
clearAllCachedValues()
Call this whenever validation structures change, so future results stay in sync with the Workbook state.
(每当验证结构发生变化时调用它,以便将来的结果与工作簿状态保持同步。)
|
DataValidationEvaluator.DataValidationContext |
getValidationContextForCell(CellReference cell)
Finds and returns the
DataValidationEvaluator.DataValidationContext for the cell, if there is one.
(查找并返回单元格的 DataValidationEvaluator.DataValidationContext(如果有)。)
|
DataValidation |
getValidationForCell(CellReference cell)
Finds and returns the
DataValidation for the cell, if there is one.
(查找并返回单元格的 DataValidation(如果有)。)
|
java.util.List<ValueEval> |
getValidationValuesForCell(CellReference cell)
If
getValidationForCell(CellReference) returns an instance, and the
DataValidationConstraint.ValidationType is
DataValidationConstraint.ValidationType.LIST , return the valid values, whether they are from a static list or cell range.
(如果 getValidationForCell(CellReference) 返回一个实例,并且 DataValidationConstraint.ValidationType 是 DataValidationConstraint.ValidationType.LIST,则返回有效值,无论它们来自静态列表还是单元格区域。)
|
protected static java.util.List<ValueEval> |
getValidationValuesForConstraint(DataValidationEvaluator.DataValidationContext context)
static so enums can reference it without creating a whole instance
(静态的,因此枚举可以引用它而无需创建整个实例)
|
protected WorkbookEvaluator |
getWorkbookEvaluator() |
static boolean |
isType(Cell cell, CellType type)
Note that this assumes the cell cached value is up to date and in sync with data edits
(请注意,这假设单元格缓存值是最新的并且与数据编辑同步)
|
boolean |
isValidCell(CellReference cellRef)
Use the validation returned by
getValidationForCell(CellReference) if you want the error display details.
(如果需要错误显示详细信息,请使用 getValidationForCell(CellReference) 返回的验证。)
|
public DataValidationEvaluator(Workbook wb, WorkbookEvaluatorProvider provider)
wb
- the workbook this operates on
(wb - 操作的工作簿)
provider
- provider for formula evaluation
(provider - 公式评估的提供者)
protected WorkbookEvaluator getWorkbookEvaluator()
public void clearAllCachedValues()
public DataValidation getValidationForCell(CellReference cell)
DataValidation
for the cell, if there is one. Lookup is based on the first match from
DataValidation.getRegions()
for the cell's sheet. DataValidation regions must be in the same sheet as the DataValidation. Allowed values expressions may reference other sheets, however.
(查找并返回单元格的 DataValidation(如果有)。查找基于 DataValidation.getRegions() 中单元格工作表的第一个匹配项。 DataValidation 区域必须与 DataValidation 位于同一工作表中。但是,允许值表达式可能会引用其他工作表。)
cell
- reference to check - use this in case the cell does not actually exist yet
(单元格 - 对检查的引用 - 在单元格实际不存在的情况下使用它)
public DataValidationEvaluator.DataValidationContext getValidationContextForCell(CellReference cell)
DataValidationEvaluator.DataValidationContext
for the cell, if there is one. Lookup is based on the first match from
DataValidation.getRegions()
for the cell's sheet. DataValidation regions must be in the same sheet as the DataValidation. Allowed values expressions may reference other sheets, however.
(查找并返回单元格的 DataValidationEvaluator.DataValidationContext(如果有)。查找基于 DataValidation.getRegions() 中单元格工作表的第一个匹配项。 DataValidation 区域必须与 DataValidation 位于同一工作表中。但是,允许值表达式可能会引用其他工作表。)
cell
- reference to check
(单元格 - 检查的参考)
public java.util.List<ValueEval> getValidationValuesForCell(CellReference cell)
getValidationForCell(CellReference)
returns an instance, and the
DataValidationConstraint.ValidationType
is
DataValidationConstraint.ValidationType.LIST
, return the valid values, whether they are from a static list or cell range.
For all other validation types, or no validation at all, this method returns null.
This method could throw an exception if the validation type is not LIST, but since this method is mostly useful in UI contexts, null seems the easier path.
(如果 getValidationForCell(CellReference) 返回一个实例,并且 DataValidationConstraint.ValidationType 是 DataValidationConstraint.ValidationType.LIST,则返回有效值,无论它们来自静态列表还是单元格区域。对于所有其他验证类型,或根本没有验证,此方法返回 null。如果验证类型不是 LIST,此方法可能会引发异常,但由于此方法在 UI 上下文中最有用,因此 null 似乎更简单。)cell
- reference to check - use this in case the cell does not actually exist yet
(单元格 - 对检查的引用 - 在单元格实际不存在的情况下使用它)
List
of
ValueEval
s if applicable, or null
(如果适用,则返回不可修改的 ValueEval 列表,或 null)
protected static java.util.List<ValueEval> getValidationValuesForConstraint(DataValidationEvaluator.DataValidationContext context)
List
of
ValueEval
s, which may be empty
(返回一个不可修改的 ValueEval 列表,可能为空)
public boolean isValidCell(CellReference cellRef)
getValidationForCell(CellReference)
if you want the error display details. This is the validation checked by this method, which attempts to replicate Excel's data validation rules.
Note that to properly apply some validations, care must be taken to offset the base validation formula by the relative position of the current cell, or the wrong value is checked.
(如果需要错误显示详细信息,请使用 getValidationForCell(CellReference) 返回的验证。这是此方法检查的验证,它尝试复制 Excel 的数据验证规则。请注意,要正确应用某些验证,必须注意将基本验证公式偏移当前单元格的相对位置,否则会检查错误的值。)cellRef
- The reference of the cell to evaluate
(cellRef - 要评估的单元格的引用)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.