Package org.zkoss.poi.ss.util

Examples of org.zkoss.poi.ss.util.CellRangeAddress


   
    final List<? extends DataValidation> dataValidations= BookHelper.getDataValidations(srcSheet);
    for(DataValidation dataValidation : dataValidations) {
      CellRangeAddressList addrList = dataValidation.getRegions();
      for(int j = addrList.countRanges(); --j >= 0;) {
        final CellRangeAddress addr = addrList.getCellRangeAddress(j);
        boolean inRange = addr.isInRange(row, col);
        if (inRange) {
          return dataValidation;
        }
      }
    }
View Full Code Here


  public static void setDataValidationToRange(Range range, Range ref){
    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

     
      final List<? extends DataValidation> dataValidations = BookHelper.getDataValidations(srcSheet);
        for(DataValidation dataValidation : dataValidations) {
          CellRangeAddressList addrList = dataValidation.getRegions();
          for(int j = addrList.countRanges(); --j >= 0;) {
            final CellRangeAddress addr = addrList.getCellRangeAddress(j);
            if (addr.isInRange(rngRow, rngCol, rngLastRow, rngLastCol)) {
              //TODO: not fully mimic the scenario as excel
              //have to remove the whole data validation first
              range.getSheet().removeValidationData(dataValidation);
              return;
            }
View Full Code Here

  }

  //TODO enhance performance for locating mergearea
  public static CellRangeAddress getMergeRegion(Worksheet sheet, int row, int col) {
    for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
      final CellRangeAddress ref = sheet.getMergedRegion(i);
      final int top = ref.getFirstRow();
          final int bottom = ref.getLastRow();
          final int left = ref.getFirstColumn();
          final int right = ref.getLastColumn();
         
          if (row >= top && row <= bottom && col >= left && col <= right) {
            return ref;
          }
    }
    return new CellRangeAddress(row, row, col, col);
  }
View Full Code Here

    final int t = rng.getFirstRow();
    final int r = rng.getLastColumn();
    final int b = rng.getLastRow();
   
    for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
      final CellRangeAddress ref = sheet.getMergedRegion(i);
      final int top = ref.getFirstRow();
          final int bottom = ref.getLastRow();
          final int left = ref.getFirstColumn();
          final int right = ref.getLastColumn();
     
          if (l == left && t == top && r == right && b == bottom) {
            return true;
          }
    }
View Full Code Here

      dstCell.setCellStyle(prepareCellStyle(srcCell.getCellStyle(), dstCell, pasteType));
      //handle merge/unmerge cases
      final int dstrow = dstCell.getRowIndex();
      final int dstcol = dstCell.getColumnIndex();
      final Worksheet dstSheet = (Worksheet)dstCell.getSheet();
      final CellRangeAddress dstaddr = ((SheetCtrl)dstSheet).getMerged(dstrow, dstcol);
      if (dstaddr != null) { //shall un-merge the destination merge range
        final int dstrow2 = dstaddr.getLastRow();
        final int dstcol2 = dstaddr.getLastColumn();
        final ChangeInfo changeInfo0 = unMerge(dstSheet, dstrow, dstcol, dstrow2, dstcol2);
        assignChangeInfo(toEval, affected, mergeChanges, changeInfo0);
      }
      final int srcrow = srcCell.getRowIndex();
      final int srccol = srcCell.getColumnIndex();
      final CellRangeAddress srcaddr = ((SheetCtrl)srcCell.getSheet()).getMerged(srcrow, srccol);
      if (srcaddr != null) { //src is a merge range, shall merge dest cell
        final int srcrow2 = srcaddr.getLastRow();
        final int srccol2 = srcaddr.getLastColumn();
        final int tRow = dstrow;
        final int lCol = dstcol;
        final int bRow = tRow + srcrow2 - srcrow;
        final int rCol = lCol + srccol2 - srccol;
        final ChangeInfo changeInfo0 = merge(dstSheet, tRow, lCol, bRow, rCol, false);
View Full Code Here

 
 
  private static List<MergeChange> prepareChangeMerges(RefSheet sheet, List<CellRangeAddress[]> shiftedRanges) {
    final List<MergeChange> changeMerges = new ArrayList<MergeChange>();
    for(CellRangeAddress[] rngs : shiftedRanges) {
      final CellRangeAddress rng = rngs[1];
      Ref ref = null;
      if (rng != null) {
        int tRow = rng.getFirstRow();
        int lCol = rng.getFirstColumn();
        int bRow = rng.getLastRow();
        int rCol = rng.getLastColumn();
        ref = new AreaRefImpl(tRow, lCol, bRow, rCol, sheet);
      }
      final CellRangeAddress orgRng = rngs[0];
      int tRow = orgRng.getFirstRow();
      int lCol = orgRng.getFirstColumn();
      int bRow = orgRng.getLastRow();
      int rCol = orgRng.getLastColumn();
      final Ref orgRef = new AreaRefImpl(tRow, lCol, bRow, rCol, sheet);
      changeMerges.add(new MergeChange(orgRef, ref));
    }
    return changeMerges;
  }
View Full Code Here

 
  public static ChangeInfo unMerge(Worksheet sheet, int tRow, int lCol, int bRow, int rCol) {
    final RefSheet refSheet = BookHelper.getRefSheet((Book)sheet.getWorkbook(), sheet);
    final List<MergeChange> changes = new ArrayList<MergeChange>();
    for(int j = sheet.getNumMergedRegions() - 1; j >= 0; --j) {
          final CellRangeAddress merged = sheet.getMergedRegion(j);
         
          final int firstCol = merged.getFirstColumn();
          final int lastCol = merged.getLastColumn();
          final int firstRow = merged.getFirstRow();
          final int lastRow = merged.getLastRow();
          if (firstCol >= lCol && lastCol <= rCol
            && firstRow >= tRow && lastRow <= bRow) { //total cover
        changes.add(new MergeChange(new AreaRefImpl(firstRow, firstCol, lastRow, lastCol, refSheet), null));
        sheet.removeMergedRegion(j);
          }
View Full Code Here

          }
        }
      }
    }
   
    sheet.addMergedRegion(new CellRangeAddress(tRow, bRow, lCol, rCol));
    final Ref mergeArea = new AreaRefImpl(tRow, lCol, bRow, rCol, BookHelper.getRefSheet((Book)sheet.getWorkbook(), sheet));
    all.add(mergeArea);
    changes.add(new MergeChange(null, mergeArea));
   
    return new ChangeInfo(last, all, changes);
View Full Code Here

          break;
        }
      }
    }
    if (area1 == null) {
      return new CellRangeAddress(-1, -1, -1, -1);
    } else {
      CellRangeAddress rng1 = new CellRangeAddress(area1.getFirstRow(), area1.getLastRow(), area1.getFirstColumn(), area1.getLastColumn());
      if (area2 == null) { //only area1
        if (rng1.isFullColumnRange()) { //repeat column
          return new CellRangeAddress(-1, -1, area1.getFirstColumn(), area1.getLastColumn())
        } else if (rng1.isFullRowRange()) { //repeat row
          return new CellRangeAddress(area1.getFirstRow(), area1.getLastRow(), -1, -1)
        }
      } else { //area1 + area2
        if (rng1.isFullColumnRange()) { //repeat column
          return new CellRangeAddress(area2.getFirstRow(), area2.getLastRow(), area1.getFirstColumn(), area1.getLastColumn())
        } else if (rng1.isFullRowRange()) { //repeat row
          return new CellRangeAddress(area1.getFirstRow(), area1.getLastRow(), area2.getFirstColumn(), area2.getLastColumn())
        }
      }
      return new CellRangeAddress(-1, -1, -1, -1);
    }
  }
View Full Code Here

TOP

Related Classes of org.zkoss.poi.ss.util.CellRangeAddress

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.