Package org.apache.poi.hssf.usermodel
Class DVConstraint
java.lang.Object
org.apache.poi.hssf.usermodel.DVConstraint
- All Implemented Interfaces:
DataValidationConstraint
Data Validation Constraint
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.poi.ss.usermodel.DataValidationConstraint
DataValidationConstraint.OperatorType, DataValidationConstraint.ValidationType -
Method Summary
Modifier and TypeMethodDescriptionstatic DVConstraintcreateCustomFormulaConstraint(String formula) static DVConstraintcreateDateConstraint(int comparisonOperator, String expr1, String expr2, String dateFormat) Creates a date based data validation constraint.static DVConstraintcreateExplicitListConstraint(String[] explicitListValues) static DVConstraintcreateFormulaListConstraint(String listFormula) static DVConstraintcreateNumericConstraint(int validationType, int comparisonOperator, String expr1, String expr2) Creates a number based data validation constraint.static DVConstraintcreateTimeConstraint(int comparisonOperator, String expr1, String expr2) Creates a time based data validation constraint.String[]If validation type isDataValidationConstraint.ValidationType.LISTandformula1was comma-separated literal values rather than a range or named range, returns list of literal values.intintbooleanConvenience methodbooleanConvenience methodvoidsetExplicitListValues(String[] explicitListValues) voidsetFormula1(String formula1) Sets a formula for expression 1.voidsetFormula2(String formula2) Sets a formula for expression 2.voidsetOperator(int operator) Sets the comparison operator for this constraintvoidsetValue1(double value1) Sets a numeric value for expression 1.voidsetValue2(double value2) Sets a numeric value for expression 2.
-
Method Details
-
createNumericConstraint
public static DVConstraint createNumericConstraint(int validationType, int comparisonOperator, String expr1, String expr2) Creates a number based data validation constraint. The text values entered for expr1 and expr2 can be either standard Excel formulas or formatted number values. If the expression starts with '=' it is parsed as a formula, otherwise it is parsed as a formatted number.- Parameters:
validationType- one ofDataValidationConstraint.ValidationType.ANY,DataValidationConstraint.ValidationType.DECIMAL,DataValidationConstraint.ValidationType.INTEGER,DataValidationConstraint.ValidationType.TEXT_LENGTHcomparisonOperator- any constant fromDataValidationConstraint.OperatorTypeenumexpr1- date formula (when first char is '=') or formatted number valueexpr2- date formula (when first char is '=') or formatted number value
-
createFormulaListConstraint
-
createExplicitListConstraint
-
createTimeConstraint
Creates a time based data validation constraint. The text values entered for expr1 and expr2 can be either standard Excel formulas or formatted time values. If the expression starts with '=' it is parsed as a formula, otherwise it is parsed as a formatted time. To parse formatted times, two formats are supported: "HH:MM" or "HH:MM:SS". This is contrary to Excel which uses the default time format from the OS.- Parameters:
comparisonOperator- constant fromDataValidationConstraint.OperatorTypeenumexpr1- date formula (when first char is '=') or formatted time valueexpr2- date formula (when first char is '=') or formatted time value
-
createDateConstraint
public static DVConstraint createDateConstraint(int comparisonOperator, String expr1, String expr2, String dateFormat) Creates a date based data validation constraint. The text values entered for expr1 and expr2 can be either standard Excel formulas or formatted date values. If the expression starts with '=' it is parsed as a formula, otherwise it is parsed as a formatted date (Excel uses the same convention). To parse formatted dates, a date format needs to be specified. This is contrary to Excel which uses the default short date format from the OS.- Parameters:
comparisonOperator- constant fromDataValidationConstraint.OperatorTypeenumexpr1- date formula (when first char is '=') or formatted date valueexpr2- date formula (when first char is '=') or formatted date valuedateFormat- ignored if both expr1 and expr2 are formulas. Default value is "YYYY/MM/DD" otherwise any other valid argument for SimpleDateFormat can be used- See Also:
-
createCustomFormulaConstraint
-
getValidationType
public int getValidationType()- Specified by:
getValidationTypein interfaceDataValidationConstraint- Returns:
- data validation type of this constraint
- See Also:
-
isListValidationType
public boolean isListValidationType()Convenience method- Returns:
trueif this constraint is a 'list' validation
-
isExplicitList
public boolean isExplicitList()Convenience method- Returns:
trueif this constraint is a 'list' validation with explicit values
-
getOperator
public int getOperator()- Specified by:
getOperatorin interfaceDataValidationConstraint- Returns:
- the operator used for this constraint
- See Also:
-
setOperator
public void setOperator(int operator) Description copied from interface:DataValidationConstraintSets the comparison operator for this constraint- Specified by:
setOperatorin interfaceDataValidationConstraint- See Also:
-
getExplicitListValues
Description copied from interface:DataValidationConstraintIf validation type isDataValidationConstraint.ValidationType.LISTandformula1was comma-separated literal values rather than a range or named range, returns list of literal values. Otherwise returnsnull.- Specified by:
getExplicitListValuesin interfaceDataValidationConstraint
-
setExplicitListValues
- Specified by:
setExplicitListValuesin interfaceDataValidationConstraint
-
getFormula1
- Specified by:
getFormula1in interfaceDataValidationConstraint- Returns:
- the formula for expression 1. May be
null
-
setFormula1
Description copied from interface:DataValidationConstraintSets a formula for expression 1.- Specified by:
setFormula1in interfaceDataValidationConstraint
-
getFormula2
- Specified by:
getFormula2in interfaceDataValidationConstraint- Returns:
- the formula for expression 2. May be
null
-
setFormula2
Description copied from interface:DataValidationConstraintSets a formula for expression 2.- Specified by:
setFormula2in interfaceDataValidationConstraint
-
getValue1
- Returns:
- the numeric value for expression 1. May be
null
-
setValue1
public void setValue1(double value1) Sets a numeric value for expression 1. -
getValue2
- Returns:
- the numeric value for expression 2. May be
null
-
setValue2
public void setValue2(double value2) Sets a numeric value for expression 2.
-