Package org.zkoss.poi.ss.usermodel

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


    for (Ref ref : all) {
      final int tRow = ref.getTopRow();
      final int lCol = ref.getLeftCol();
      final Worksheet srcSheet = getSheet(sheet, ref.getOwnerSheet());
      final Book srcBook = (Book) srcSheet.getWorkbook();
      final Cell srcCell = getCell(srcSheet, tRow, lCol);
      if (srcCell != null && srcCell.getCellType() == Cell.CELL_TYPE_FORMULA) {
        final int sheetIndex = srcBook.getSheetIndex(srcSheet);
        if (srcBook.getSpreadsheetVersion() == SpreadsheetVersion.EXCEL97) {
          shiftHSSFFormulas(shifter97, sheetIndex, srcCell);
        } else {
          shiftXSSFFormulas(shifter2007, sheetIndex, (XSSFCell)srcCell, (XSSFWorkbook)srcBook);
View Full Code Here


  private static ChangeInfo merge0(Worksheet sheet, int tRow, int lCol, int bRow, int rCol) {
    final List<MergeChange> changes = new ArrayList<MergeChange>();
    final Set<Ref> all = new HashSet<Ref>();
    final Set<Ref> last = new HashSet<Ref>();
    //find the left most non-blank cell.
    Cell target = null;
    for(int r = tRow; target == null && r <= bRow; ++r) {
      for(int c = lCol; c <= rCol; ++c) {
        final Cell cell = BookHelper.getCell(sheet, r, c);
        if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
          target = cell;
          break;
        }
      }
    }
   
    CellStyle style = null;
    if (target != null) { //found the target
      final int tgtRow = target.getRowIndex();
      final int tgtCol = target.getColumnIndex();
      final int nRow = tRow - tgtRow;
      final int nCol = lCol - tgtCol;
      if (nRow != 0 || nCol != 0) { //if target not the left-top one, move to left-top
        final ChangeInfo info = BookHelper.moveRange(sheet, tgtRow, tgtCol, tgtRow, tgtCol, nRow, nCol);
        if (info != null) {
          changes.addAll(info.getMergeChanges());
          last.addAll(info.getToEval());
          all.addAll(info.getAffected());
        }
      }
      final CellStyle source = target.getCellStyle();
      style = source.getIndex() == 0 ? null : sheet.getWorkbook().createCellStyle();
      if (style != null) {
        style.cloneStyleFrom(source);
        style.setBorderLeft(CellStyle.BORDER_NONE);
        style.setBorderTop(CellStyle.BORDER_NONE);
        style.setBorderRight(CellStyle.BORDER_NONE);
        style.setBorderBottom(CellStyle.BORDER_NONE);
        target.setCellStyle(style); //set all cell in the merged range to CellStyle of the target minus border
      }
      //1st row (exclude 1st cell)
      for (int c = lCol + 1; c <= rCol; ++c) {
        final Cell cell = getOrCreateCell(sheet, tRow, c);
        cell.setCellStyle(style); //set all cell in the merged range to CellStyle of the target minus border
        final Set<Ref>[] refs = BookHelper.setCellValue(cell, (RichTextString) null);
        if (refs != null) {
          last.addAll(refs[0]);
          all.addAll(refs[1]);
        }
      }
      //2nd row and after
      for(int r = tRow+1; r <= bRow; ++r) {
        for(int c = lCol; c <= rCol; ++c) {
          final Cell cell = getOrCreateCell(sheet, r, c);
          cell.setCellStyle(style); //set all cell in the merged range to CellStyle of the target minus border
          final Set<Ref>[] refs = BookHelper.setCellValue(cell, (RichTextString) null);
          if (refs != null) {
            last.addAll(refs[0]);
            all.addAll(refs[1]);
          }
View Full Code Here

      endCol = Math.min(rCol, endCol);
      for (int colnum = begCol; colnum <= endCol; ++colnum) {
        final Object[] values = new Object[keyCount];
        for(int j = 0; j < keyCount; ++j) {
          final Row row = sheet.getRow(keyIndexes[j]);
          final Cell cell = row != null ? row.getCell(colnum, Row.RETURN_BLANK_AS_NULL) : null;
          final Object val = getCellObject(cell, dataOptions[j]);
          values[j] = val;
        }
        final SortKey sortKey = new SortKey(colnum, values);
        sortKeys.add(sortKey);
      }
      if (!sortKeys.isEmpty()) {
        final Comparator<SortKey> keyComparator = new KeyComparator(descs, matchCase, sortMethod, type);
        Collections.sort(sortKeys, keyComparator);
        return BookHelper.assignColumns(sheet, sortKeys, begRow, lCol, endRow, rCol);
      } else {
        return null;
      }
    } else { //sortByColumn, default case
      for (int rownum = begRow; rownum <= endRow; ++rownum) {
        final Row row = sheet.getRow(rownum);
        if (row == null) {
          continue; //nothing to sort
        }
        final Object[] values = new Object[keyCount];
        for(int j = 0; j < keyCount; ++j) {
          final Cell cell = row.getCell(keyIndexes[j], Row.RETURN_BLANK_AS_NULL);
          final Object val = getCellObject(cell, dataOptions[j]);
          values[j] = val;
        }
        final SortKey sortKey = new SortKey(rownum, values);
        sortKeys.add(sortKey);
View Full Code Here

        continue;
      }
      //remove cells from the old column of the Range
      final List<Cell> cells = new ArrayList<Cell>(cellCount);
      for(int k = tRow; k <= bRow; ++k) {
        final Cell cell = BookHelper.getCell(sheet, k, oldColNum);
        if (cell != null) {
          cells.add(cell);
          final Set<Ref>[] refs = BookHelper.removeCell(cell, false);
          toEval.addAll(refs[0]);
          affected.addAll(refs[1]);
        }
      }
      if (!cells.isEmpty()) {
        newCols.put(Integer.valueOf(newColNum), cells);
      }
    }
   
    //move cells
    for(Entry<Integer, List<Cell>> entry : newCols.entrySet()) {
      final int colNum = entry.getKey().intValue();
      final List<Cell> cells = entry.getValue();
      for(Cell cell : cells) {
        final int rowNum = cell.getRowIndex();
        final ChangeInfo changeInfo0 = BookHelper.copyCell(cell, sheet, rowNum, colNum, Range.PASTE_ALL, Range.PASTEOP_NONE, false);
        assignChangeInfo(toEval, affected, mergeChanges, changeInfo0);
      }
    }
    return changeInfo;
View Full Code Here

      //remove cells from the old row of the Range
      final List<Cell> cells = new ArrayList<Cell>(cellCount);
      final int begCol = Math.max(lCol, row.getFirstCellNum());
      final int endCol = Math.min(rCol, row.getLastCellNum() - 1);
      for(int k = begCol; k <= endCol; ++k) {
        final Cell cell = row.getCell(k);
        if (cell != null) {
          cells.add(cell);
          final Set<Ref>[] refs = BookHelper.removeCell(cell, false);
          assignRefs(toEval, affected, refs);
        }
      }
      if (!cells.isEmpty()) {
        newRows.put(Integer.valueOf(newRowNum), cells);
      }
    }
   
    //move cells
    for(Entry<Integer, List<Cell>> entry : newRows.entrySet()) {
      final int rowNum = entry.getKey().intValue();
      final List<Cell> cells = entry.getValue();
      for(Cell cell : cells) {
        final int colNum = cell.getColumnIndex();
        final ChangeInfo changeInfo0 = BookHelper.copyCell(cell, sheet, rowNum, colNum, Range.PASTE_ALL, Range.PASTEOP_NONE, false);
        assignChangeInfo(toEval, affected, mergeChanges, changeInfo0);
      }
    }
    return changeInfo;
View Full Code Here

  }
 
  public static Set<Ref> setCellStyle(Worksheet sheet, int tRow, int lCol, int bRow, int rCol, CellStyle style) {
    for(int r = tRow; r <= bRow; ++r) {
      for (int c = lCol; c <= rCol; ++c) {
        final Cell cell = BookHelper.getOrCreateCell(sheet, r, c);
        cell.setCellStyle(style);
      }
    }
    final Set<Ref> all = new HashSet<Ref>(1);
    final RefSheet refSheet = BookHelper.getRefSheet((Book)sheet.getWorkbook(), sheet);
    all.add(new AreaRefImpl(tRow, lCol, bRow, rCol, refSheet));
View Full Code Here

      parts[j++]= -1;
    }
    return parts;
  }
  private static Step getTimeStep(Cell[] srcCells, int b, int e, boolean positive, int fillType, int subType) {
    final Cell srcCell1 = srcCells[b];
    if (b == e) { //only one srcCell
      return new MsecondStep(srcCell1.getDateCellValue(), positive ? 60*60*1000 : -60*60*1000, subType);
    }
   
    //more than one srcCell
    Date date1 = srcCell1.getDateCellValue();
    Cell srcCell2 = srcCells[b+1];
    Date date2 = srcCell2.getDateCellValue();
    final long step = date2.getTime() - date1.getTime();
      for(int k = b+2; k <= e; ++k) {
        srcCell2 = srcCells[k];
        date1 = date2;
        date2 = srcCell2.getDateCellValue();
        if (step != (date2.getTime() - date1.getTime())) {
          return CopyStep.instance;
        }
      }
    return new MsecondStep(date2, step, subType);
View Full Code Here

      fillType = FILL_DAYS;
    }
    return myGetDateStep(srcCells, b, e, positive, fillType, subType);
  }
  private static Step myGetDateStep(Cell[] srcCells, int b, int e, boolean positive, int fillType, int subType) {
    final Cell srcCell1 = srcCells[b];
    final int[] time1 = getTimeParts(srcCell1);
      int j = 0;
      int y1 = time1[j]; ++j;
      int m1 = time1[j]; ++j;
      int d1 = time1[j]; ++j;
      int h1 = time1[j]; ++j;
      int min1 = time1[j]; ++j;
      int s1 = time1[j]; ++j;
      int ms1 = time1[j];
      int t1 = (h1 < 0 ? 0 : h1 * 60 * 60 * 1000) + min1 * 60 * 1000 + s1 * 1000 + ms1;
    if (b == e) { //only one srcCell
      switch(fillType) {
      case FILL_DAYS:
        return new MsecondStep(srcCells[b].getDateCellValue(), positive ? 24*60*60*1000 : -24*60*60*1000, subType);
      case FILL_HOURS:
        return new MsecondStep(srcCells[b].getDateCellValue(), positive ? 60*60*1000 : -60*60*1000, subType);
      case FILL_MONTHS:
        return new DateStep(y1, m1, d1, t1, positive ? 1 : -1, 0, subType);
      case FILL_YEARS:
        return new DateStep(y1, m1, d1, t1, positive ? 12 : -12, 0, subType);
      case FILL_WEEKDAYS:
        return new MsecondStep(srcCells[b].getDateCellValue(), positive ? 7*24*60*60*1000 : -7*24*60*60*1000, subType);
      default:
        return CopyStep.instance;
      }
    }
   
    //more than one srcCell
      final Cell srcCell2  = srcCells[b+1];
      final int[] time2 = getTimeParts(srcCell2);
      j = 0;
      int y2 = time2[j]; ++j;
      int m2 = time2[j]; ++j;
      int d2 = time2[j]; ++j;
      int h2 = time2[j]; ++j;
      int min2 = time2[j]; ++j;
      int s2 = time2[j]; ++j;
      int ms2 = time2[j];
      int diffM = m2 - m1 + (y2 - y1) * 12;
      int diffD = d2 - d1;
      if (h1 < 0 && h2 >= 0) {
        h1 = h2;
        min1 = min2;
        s1 = s2;
        ms1 = ms2;
      } else if (h1 >= 0 && h2 < 0) {
        h2 = h1;
        min2 = min1;
        s2 = s1;
        ms2 = ms1;
      }
      int t2 = (h2 < 0 ? 0 : h2 * 60 * 60 * 1000) + min2 * 60 * 1000 + s2 * 1000 + ms2;
      int diffT = t2 - t1;
      for(int k = b+2; k <= e; ++k) {
          y1 = y2;
          m1 = m2;
          d1 = d2;
          h1 = h2;
          min1 = min2;
          s1 = s2;
          ms1 = ms2;
          t1 = t2;
         
          final Cell srcCell = srcCells[k];
          final int[] time = getTimeParts(srcCell);
          j = 0;
          y2 = time[j]; ++j;
          m2 = time[j]; ++j;
          d2 = time[j]; ++j;
View Full Code Here

    double prev = srcCells[b].getNumericCellValue();
    double curv = srcCells[b+1].getNumericCellValue();
    double ratio = curv / prev;
    prev = curv;
    for (int k = b+2; k <=e; ++k) {
      final Cell srcCell = srcCells[k];
      curv = srcCell.getNumericCellValue();
      if (ratio != (curv / prev)) {
        return CopyStep.instance;
      }
      prev = curv;
    }
View Full Code Here

  }
  private static Step getLinearStep(Cell[] srcCells, int b, int e, boolean positive) {
    int count = e-b+1;
    final double[] values = new double[count];
    for (int j = 0, k = b; k <=e; ++k) {
      final Cell srcCell = srcCells[k];
      values[j++] = srcCell.getNumericCellValue();
    }
    if (count == 1) {
      final double step = positive ? 1 : -1;
      return new LinearStep(values[count-1], step, step, Step.NUMBER);
    } else if (count == 2) { //standard linear series
View Full Code Here

TOP

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

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.