List of usage examples for org.apache.poi.ss.usermodel DataValidationHelper createNumericConstraint
DataValidationConstraint createNumericConstraint(int validationType, int operatorType, String formula1, String formula2);
From source file:com.plugin.excel.util.ExcelFileHelper.java
License:Apache License
private static void addNumberValidation(Cell cell) { if (cell != null) { Sheet sheet = cell.getSheet();/*w w w. j a v a 2 s . co m*/ DataValidationHelper dvHelper = sheet.getDataValidationHelper(); XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper .createNumericConstraint(ValidationType.DECIMAL, DVConstraint.OperatorType.BETWEEN, "1.00", "1000000000000.00"); CellRangeAddressList addressList = new CellRangeAddressList(cell.getRowIndex(), cell.getRowIndex(), cell.getColumnIndex(), cell.getColumnIndex()); XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList); validation.setErrorStyle(ErrorStyle.STOP); validation.createErrorBox("Error", "Only numeric values are allowed"); validation.setShowErrorBox(true); sheet.addValidationData(validation); } }