Package org.zkoss.poi.ss.usermodel

Examples of org.zkoss.poi.ss.usermodel.DataValidationConstraint


        }
        if (!srcInRange) { //this validation is not associated to source cell
          continue;
        }
        //so we shall copy this data validation to dst cell
        final DataValidationConstraint constraint = BookHelper.getConstraint(dataValidation);
        DataValidation dstDataValidation = BookHelper.getDataValidationByConstraint(constraint, getDataValidations(dstSheet));
        if (dstDataValidation == null) {
          final CellRangeAddressList dstAddrList = new CellRangeAddressList(dstRow, dstCol, dstRow, dstCol);
          dstDataValidation = helper.createValidation(constraint, dstAddrList);
          dstSheet.addValidationData(dstDataValidation);
View Full Code Here


  public static void setDataValidationToRange(Range range, String[] list) {
    if (range.getSheet() instanceof HSSFSheet) {
      //TODO: not yet implemented for 2003
    }else{
      final DataValidationHelper helper = range.getSheet().getDataValidationHelper();
      DataValidationConstraint constraint = new XSSFDataValidationConstraint(list);
      CellRangeAddressList dstAddrList = new CellRangeAddressList(range.getRow(),range.getLastRow(), range.getColumn(), range.getLastColumn());   
      DataValidation dstDataValidation = helper.createValidation(constraint, dstAddrList);
      range.getSheet().addValidationData(dstDataValidation);     
    }
  }
View Full Code Here

    if (range.getSheet() instanceof HSSFSheet) {
      //TODO: not yet implemented for 2003
    }else{
      final DataValidationHelper helper = range.getSheet().getDataValidationHelper();
      CellRangeAddress refCRA = new CellRangeAddress(ref.getRow(),ref.getLastRow(),ref.getColumn(),ref.getLastColumn());
      DataValidationConstraint constraint = new XSSFDataValidationConstraint(ValidationType.LIST,convertToAbsoluteString(refCRA));
      CellRangeAddressList dstAddrList = new CellRangeAddressList(range.getRow(),range.getLastRow(), range.getColumn(), range.getLastColumn());   
      DataValidation dstDataValidation = helper.createValidation(constraint, dstAddrList);
      range.getSheet().addValidationData(dstDataValidation);           
   
  }
View Full Code Here

    return false;
  }
 
  //get validation list, null if not a LIST validation.
  public static String[] getValidationList(Worksheet sheet, DataValidation validation) {
    DataValidationConstraint constraint = validation.getValidationConstraint();
    if (constraint.getValidationType() != ValidationType.LIST) {
      return null;
    }
    String[] list = constraint.getExplicitListValues();
    if (list != null) {
      return list;
    }
    String txt = constraint.getFormula1();
    Book book = sheet.getBook();
    final ValueEval ve = BookHelper.evaluateFormulaValueEval(book, book.getSheetIndex(sheet), txt, true);
    if (ve instanceof AreaEval) {
      final AreaEval ae = (AreaEval) ve;
      if (ae.isColumn() || ae.isRow()) {
View Full Code Here

    DataValidation dv = sheet.getDataValidation(row, col);
    //no validation constraint
    if (dv == null) {
      return null;
    }
    final DataValidationConstraint constraint = dv.getValidationConstraint();
    //allow any value => no need to do validation
    if (constraint.getValidationType() == ValidationType.ANY) { //can be any value, meaning no validation
      return null;
    }
    //ignore empty and value is empty
    if (value == null || (value instanceof String && ((String)value).length() == 0)) {
      if (dv.getEmptyCellAllowed()) {
        return null;
      }
    }
    //get new evaluated formula value
    if (cellType == Cell.CELL_TYPE_FORMULA) {
      final Book book = sheet.getBook();
      final int sheetIndex = book.getSheetIndex(sheet);
      final CellValue cv = BookHelper.evaluateFormula(book, sheetIndex, (String) value);
      value = BookHelper.getValueByCellValue(cv);
      cellType = cv.getCellType();
    }
    //start validation
    boolean success = true;
    switch(constraint.getValidationType()) {
      // Integer ('Whole number') type
      case ValidationType.INTEGER:
        if (!isInteger(value) || !validateOperation(sheet, constraint, (Number)value)) {
          success = false;
        }
View Full Code Here

    @Override
    public void visitRecord(Record r) {
      if (r instanceof DVRecord) {
        final DVRecord dvRecord = (DVRecord) r;
        final CellRangeAddressList regions = dvRecord.getCellRangeAddress();
        final DataValidationConstraint constraint = createContraint(dvRecord);
        if (constraint != null) {
          HSSFDataValidation dataValidation = new HSSFDataValidation(regions, constraint);
          final boolean allowed = dvRecord.getEmptyCellAllowed();
          final int errStyle = dvRecord.getErrorStyle();
          final boolean showErr = dvRecord.getShowErrorOnInvalidValue();
View Full Code Here

  private void initValidation() {
    DataValidationHelper dvh = sheet.getDataValidationHelper();
    String[] vals = { "STFI", "Treasury", "Fixed Income", "Trade Capture",
        "Unknow" };
    DataValidationConstraint dvc = dvh.createExplicitListConstraint(vals);
    CellRangeAddressList cral = new CellRangeAddressList(1, 100, 3, 3);
    DataValidation dv = dvh.createValidation(dvc, cral);
    sheet.addValidationData(dv);
  }
View Full Code Here

TOP

Related Classes of org.zkoss.poi.ss.usermodel.DataValidationConstraint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.