/** * 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. * * @param comparisonOperator constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum * @param expr1 date formula (when first char is '=') or formatted time value * @param expr2 date formula (when first char is '=') or formatted time value */ public static DVConstraint createTimeConstraint(int comparisonOperator, String expr1, String expr2) { if (expr1 == null) { throw new IllegalArgumentException("expr1 must be supplied"); } OperatorType.validateSecondArg(comparisonOperator, expr1); // formula1 and value1 are mutually exclusive String formula1 = getFormulaFromTextExpression(expr1); Double value1 = formula1 == null ? convertTime(expr1) : null; // formula2 and value2 are mutually exclusive String formula2 = getFormulaFromTextExpression(expr2); Double value2 = formula2 == null ? convertTime(expr2) : null; return new DVConstraint(ValidationType.TIME, comparisonOperator, formula1, formula2, value1, value2, null); }
/** * 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. * * @param comparisonOperator constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum * @param expr1 date formula (when first char is '=') or formatted time value * @param expr2 date formula (when first char is '=') or formatted time value */ public static DVConstraint createTimeConstraint(int comparisonOperator, String expr1, String expr2) { if (expr1 == null) { throw new IllegalArgumentException("expr1 must be supplied"); } OperatorType.validateSecondArg(comparisonOperator, expr1); // formula1 and value1 are mutually exclusive String formula1 = getFormulaFromTextExpression(expr1); Double value1 = formula1 == null ? convertTime(expr1) : null; // formula2 and value2 are mutually exclusive String formula2 = getFormulaFromTextExpression(expr2); Double value2 = formula2 == null ? convertTime(expr2) : null; return new DVConstraint(ValidationType.TIME, comparisonOperator, formula1, formula2, value1, value2, null); }
/** * 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. * * @param comparisonOperator constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum * @param expr1 date formula (when first char is '=') or formatted time value * @param expr2 date formula (when first char is '=') or formatted time value */ public static DVConstraint createTimeConstraint(int comparisonOperator, String expr1, String expr2) { if (expr1 == null) { throw new IllegalArgumentException("expr1 must be supplied"); } OperatorType.validateSecondArg(comparisonOperator, expr1); // formula1 and value1 are mutually exclusive String formula1 = getFormulaFromTextExpression(expr1); Double value1 = formula1 == null ? convertTime(expr1) : null; // formula2 and value2 are mutually exclusive String formula2 = getFormulaFromTextExpression(expr2); Double value2 = formula2 == null ? convertTime(expr2) : null; return new DVConstraint(VT.TIME, comparisonOperator, formula1, formula2, value1, value2, null); }
/** * 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. * * @param comparisonOperator constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum * @param expr1 date formula (when first char is '=') or formatted time value * @param expr2 date formula (when first char is '=') or formatted time value */ public static DVConstraint createTimeConstraint(int comparisonOperator, String expr1, String expr2) { if (expr1 == null) { throw new IllegalArgumentException("expr1 must be supplied"); } OperatorType.validateSecondArg(comparisonOperator, expr1); // formula1 and value1 are mutually exclusive String formula1 = getFormulaFromTextExpression(expr1); Double value1 = formula1 == null ? convertTime(expr1) : null; // formula2 and value2 are mutually exclusive String formula2 = getFormulaFromTextExpression(expr2); Double value2 = formula2 == null ? convertTime(expr2) : null; return new DVConstraint(VT.TIME, comparisonOperator, formula1, formula2, value1, value2, null); }