public static List<InputRule> getInputRules(Sheet sheet) { List<InputRule> ret = new ArrayList<InputRule>(); if (sheet instanceof XSSFSheet) { XSSFSheet xs = (XSSFSheet)sheet; for (XSSFDataValidation dv : xs.getDataValidations()) { ret.add(new InputRule(sheet, dv)); } List<Element> extList = new ExtDataValidationExtractor().getDataValidationNode(xs); for (Element el : extList) { InputRule rule = InputRule.fromDataValidationNode(xs, el); if (rule != null) { ret.add(rule); } } } return ret; }
private void insertDropBox(XSSFDataValidationHelper dvHelper, XSSFSheet sheetTracing, int row, int col, String ref) { if (dvHelper != null) { XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createFormulaListConstraint(ref); CellRangeAddressList addressList = new CellRangeAddressList(row, row, col, col); XSSFDataValidation validation = (XSSFDataValidation)dvHelper.createValidation(dvConstraint, addressList); validation.setShowErrorBox(true); validation.setSuppressDropDownArrow(true); validation.setShowPromptBox(true); sheetTracing.addValidationData(validation); } }
private void insertCondition(XSSFDataValidationHelper dvHelper, XSSFSheet sheetTracing, int row, int col, String min, String max) { if (dvHelper != null) { XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createIntegerConstraint(OperatorType.BETWEEN, min, max); // dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(new String[]{"0000011", "0000021", "0000031"}); CellRangeAddressList addressList = new CellRangeAddressList(row, row, col, col); XSSFDataValidation validation = (XSSFDataValidation)dvHelper.createValidation(dvConstraint, addressList); validation.setShowErrorBox(true); validation.setSuppressDropDownArrow(true); validation.setShowPromptBox(true); sheetTracing.addValidationData(validation); } }
private void insertDecCondition(XSSFDataValidationHelper dvHelper, XSSFSheet sheetTracing, int row, int col) { if (dvHelper != null) { XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createDecimalConstraint(OperatorType.GREATER_OR_EQUAL, "0", ""); // dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(new String[]{"0000011", "0000021", "0000031"}); CellRangeAddressList addressList = new CellRangeAddressList(row, row, col, col); XSSFDataValidation validation = (XSSFDataValidation)dvHelper.createValidation(dvConstraint, addressList); validation.setShowErrorBox(true); validation.setSuppressDropDownArrow(true); validation.setShowPromptBox(true); sheetTracing.addValidationData(validation); } }
public InputRule(Sheet sheet, XSSFDataValidation dv) { empty = dv.getEmptyCellAllowed(); if (dv.getShowErrorBox()) { errTitle = dv.getErrorBoxTitle(); errText = dv.getErrorBoxText(); errStyle = dv.getErrorStyle(); } if (dv.getShowPromptBox()) { pmTitle = dv.getPromptBoxTitle(); pmText = dv.getPromptBoxText(); } regions = dv.getRegions(); regionsStr = new String[regions.countRanges()]; int idx = 0; for (CellRangeAddress cell : regions.getCellRangeAddresses()) { regionsStr[idx++] = cell.formatAsString(); } DataValidationConstraint vc = dv.getValidationConstraint(); f1 = vc.getFormula1(); f2 = vc.getFormula2(); op = vc.getOperator(); vt = vc.getValidationType(); if (vt == DataValidationConstraint.ValidationType.LIST) { list = buildList(sheet, f1); } }
public List<ValidationResult> validateSheet(XSSFSheet sheet) { List<ValidationResult> results = new LinkedList<ValidationResult>(); List<XSSFDataValidation> dataValidations = sheet.getDataValidations(); for (XSSFDataValidation xssfDataValidation : dataValidations) { DataValidationConstraint validationConstraint = xssfDataValidation.getValidationConstraint(); CellRangeAddressList regions = xssfDataValidation.getRegions(); CellRangeAddress[] cellRangeAddresses = regions.getCellRangeAddresses(); Validator validator = buildValidator(sheet, validationConstraint); for (CellRangeAddress cellRangeAddress : cellRangeAddresses) { int firstRow = Math.max(cellRangeAddress.getFirstRow(), sheet.getFirstRowNum()); int lastRow = Math.min(cellRangeAddress.getLastRow(), sheet.getLastRowNum()); for (int i = firstRow; i <= lastRow; i++) { XSSFRow row = sheet.getRow(i); if (row == null || row.getFirstCellNum() < 0) { continue; } int firstColumn = Math.max(cellRangeAddress.getFirstColumn(), row.getFirstCellNum()); int lastColumn = Math.min(cellRangeAddress.getLastColumn(), row.getLastCellNum()); for (int j = firstColumn; j <= lastColumn; j++) { XSSFCell cell = row.getCell(j); if (cell == null) { continue; } boolean inRange = cellRangeAddress.isInRange(cell.getRowIndex(), cell.getColumnIndex()); if (inRange) { ValidationResult result = validator.validate(cell); if (result != null) { results.add(result); } } } } } } return results; /* * TODO think about splitting this function into 2 parts: 1. * getAllValidators 2. validate with all validators */ }