Package org.zkoss.poi.ss.usermodel

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


//            if (srcStyle != null) {
//              row.setRowStyle((HSSFCellStyle)copyFromStyleExceptBorder(srcStyle));//style
//            }
            if (srcCells != null) {
              for (Entry<Integer, Cell> cellEntry : srcCells.entrySet()) {
                final Cell srcCell = cellEntry.getValue();
                final CellStyle cellStyle = srcCell.getCellStyle();
                final int c = cellEntry.getKey().intValue();
                Cell cell = row.getCell(c);
                if (cell == null) {
                  cell = row.createCell(c);
                }
                cell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), cellStyle));
              }
            }
          }
        }
       
View Full Code Here


        removePairs.add(new int[] {start, end});
      }
    }
    private void removeCells(Row row, int lCol, int rCol) {
      for(int j = lCol; j <= rCol; ++j) {
        Cell cell = row.getCell(j);
        if (cell != null) {
          row.removeCell(cell);
        }
      }
    }
View Full Code Here

              if (colNum > maxColNum)
                maxColNum = colNum;
            }
           
            if (cells != null) {
               final Cell cell = row.getCell(srcCol);
               if (cell != null) {
                 cells.put(Integer.valueOf(rowNum), cell);
               }
            }
           
            shiftCells(row, startCol, endCol, n, clearRest);
        }
       
        if (endCol < 0) {
          endCol = maxColNum;
        }
        if (n > 0) {
          if (startCol > endCol) { //nothing to do
            return Collections.emptyList();
          }
        } else {
          if ((startCol + n) > endCol) { //nothing to do
            return Collections.emptyList();
          }
        }
       
        final int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
        final int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
        final List<CellRangeAddress[]> shiftedRanges = BookHelper.shiftMergedRegion(this, 0, startCol, maxrow, endCol, n, true);
       
        //TODO handle the page breaks
        //?

        // Move comments from the source column to the
        //  destination column. Note that comments can
        //  exist for cells which are null
        if (moveComments) {
            final CommentsTable sheetComments = getCommentsTable(false);
            if(sheetComments != null){
                //TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
                CTCommentList lst = sheetComments.getCTComments().getCommentList();
                for (final Iterator<CTComment> it = lst.getCommentList().iterator(); it.hasNext();) {
                  CTComment comment = it.next();
                    CellReference ref = new CellReference(comment.getRef());
                    final int colnum = ref.getCol();
                    if(startCol <= colnum && colnum <= endCol){
                      int newColNum = colnum + n;
                      if (newColNum < 0 || newColNum > maxcol) { //out of bound, shall remove it
                        it.remove();
                      } else {
                          ref = new CellReference(ref.getRow(), newColNum);
                          comment.setRef(ref.formatAsString());
                      }
                    }
                }
            }
        }
       
        // Fix up column width if required
        int s, inc;
        if (n < 0) {
            s = startCol;
            inc = 1;
        } else {
            s = endCol;
            inc = -1;
        }

        if (copyColWidth || resetOriginalColWidth) {
          final int defaultColumnWidth = getDefaultColumnWidth();
          for ( int colNum = s; colNum >= startCol && colNum <= endCol && colNum >= 0 && colNum <= maxcol; colNum += inc ) {
            final int newColNum = colNum + n;
            if (copyColWidth) {
                setColumnWidth(newColNum, getColumnWidth(colNum));
            }
            if (resetOriginalColWidth) {
                setColumnWidth(colNum, defaultColumnWidth);
            }
          }
        }

        //handle inserted columns
        if (srcCol >= 0) {
          final int col2 = Math.min(startCol + n - 1, maxcol);
          for (int col = startCol; col <= col2 ; ++col) {
            //copy the column width
            setColumnWidth(col, colWidth);
            if (colStyle != null) {
              setDefaultColumnStyle(col, BookHelper.copyFromStyleExceptBorder(getBook(), colStyle));
            }
          }
          if (cells != null) {
            for (Entry<Integer, Cell> cellEntry : cells.entrySet()) {
                final XSSFRow row = getRow(cellEntry.getKey().intValue());
                final Cell srcCell = cellEntry.getValue();
                final CellStyle srcStyle = srcCell.getCellStyle();
              for (int col = startCol; col <= col2; ++col) {
                Cell dstCell = row.getCell(col);
                if (dstCell == null) {
                  dstCell = row.createCell(col);
                }
                dstCell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), srcStyle));
              }
            }
          }
        }
       
View Full Code Here

      //remove those not existing cells
      for(int[] pair : removePairs) {
        final int start = Math.max(0, pair[0]);
        final int end = Math.min(maxcol + 1, pair[1]);
        for(int j=start; j < end; ++j) {
          Cell cell = row.getCell(j);
          if (cell != null) {
            row.removeCell(cell);
          }
        }
      }
View Full Code Here

                if (colNum > maxColNum)
                  maxColNum = colNum;
              }
             
              if (cells != null) {
                 final Cell cell = row.getCell(srcCol);
                 if (cell != null) {
                   cells.put(Integer.valueOf(rowNum), cell);
                 }
              }
             
              shiftCells(row, startCol, endCol, n, clearRest);
          }
      }
       
        if (endCol < 0) {
          endCol = maxColNum;
        }
        if (n > 0) {
          if (startCol > endCol) { //nothing to do
            return Collections.emptyList();
          }
        } else {
          if ((startCol + n) > endCol) { //nothing to do
            return Collections.emptyList();
          }
        }
       
        final int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
        final int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
        final List<CellRangeAddress[]> shiftedRanges = BookHelper.shiftMergedRegion(this, tRow, startCol, bRow, endCol, n, true);
        final boolean wholeColumn = tRow == 0 && bRow == maxrow;
        if (wholeColumn) {
          //TODO handle the page breaks
          //?
        }

        // Move comments from the source column to the
        //  destination column. Note that comments can
        //  exist for cells which are null
        if (moveComments) {
            final CommentsTable sheetComments = getCommentsTable(false);
            if(sheetComments != null){
                //TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
                CTCommentList lst = sheetComments.getCTComments().getCommentList();
                for (final Iterator<CTComment> it = lst.getCommentList().iterator(); it.hasNext();) {
                  CTComment comment = it.next();
                    CellReference ref = new CellReference(comment.getRef());
                    final int colnum = ref.getCol();
                    final int rownum = ref.getRow();
                    if(startCol <= colnum && colnum <= endCol && tRow <= rownum && rownum <= bRow){
                      int newColNum = colnum + n;
                      if (newColNum < 0 || newColNum > maxcol) { //out of bound, shall remove it
                        it.remove();
                      } else {
                          ref = new CellReference(ref.getRow(), newColNum);
                          comment.setRef(ref.formatAsString());
                      }
                    }
                }
            }
        }
       
        // Fix up column width if required
        int s, inc;
        if (n < 0) {
            s = startCol;
            inc = 1;
        } else {
            s = endCol;
            inc = -1;
        }

        if (wholeColumn && (copyColWidth || resetOriginalColWidth)) {
          final int defaultColumnWidth = getDefaultColumnWidth();
          for ( int colNum = s; colNum >= startCol && colNum <= endCol && colNum >= 0 && colNum <= maxcol; colNum += inc ) {
            final int newColNum = colNum + n;
            if (copyColWidth) {
                setColumnWidth(newColNum, getColumnWidth(colNum));
            }
            if (resetOriginalColWidth) {
                setColumnWidth(colNum, defaultColumnWidth);
            }
          }
        }

        //handle inserted columns
        if (srcCol >= 0) {
          final int col2 = Math.min(startCol + n - 1, maxcol);
          if (wholeColumn) {
            for (int col = startCol; col <= col2 ; ++col) {
              //copy the column width
              setColumnWidth(col, colWidth);
              if (colStyle != null) {
                setDefaultColumnStyle(col, BookHelper.copyFromStyleExceptBorder(getBook(), colStyle));
              }
            }
          }
          if (cells != null) {
            for (Entry<Integer, Cell> cellEntry : cells.entrySet()) {
                final XSSFRow row = getRow(cellEntry.getKey().intValue());
                final Cell srcCell = cellEntry.getValue();
                final CellStyle srcStyle = srcCell.getCellStyle();
              for (int col = startCol; col <= col2; ++col) {
                Cell dstCell = row.getCell(col);
                if (dstCell == null) {
                  dstCell = row.createCell(col);
                }
                dstCell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), srcStyle));
              }
            }
          }
        }
       
View Full Code Here

            if (srcStyle != null) {
              row.setRowStyle((HSSFCellStyle)BookHelper.copyFromStyleExceptBorder(getBook(), srcStyle));//style
            }
            if (srcCells != null) {
              for (Entry<Integer, Cell> cellEntry : srcCells.entrySet()) {
                final Cell srcCell = cellEntry.getValue();
                final CellStyle cellStyle = srcCell.getCellStyle();
                final int c = cellEntry.getKey().intValue();
                Cell cell = row.getCell(c);
                if (cell == null) {
                  cell = row.createCell(c);
                }
                cell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), cellStyle));
              }
            }
          }
        }
       
View Full Code Here

              if (colNum > maxColNum)
                maxColNum = colNum;
            }
           
            if (cells != null) {
               final Cell cell = row.getCell(srcCol);
               if (cell != null) {
                 cells.put(Integer.valueOf(rowNum), cell);
               }
            }
           
            row.shiftCells(startCol, endCol, n, clearRest);
        }
       
        if (endCol < 0) {
          endCol = maxColNum;
        }
        if (n > 0) {
          if (startCol > endCol) { //nothing to do
            return Collections.emptyList();
          }
        } else {
          if ((startCol + n) > endCol) { //nothing to do
            return Collections.emptyList();
          }
        }
       
        int s, inc;
        if (n < 0) {
            s = startCol;
            inc = 1;
        } else {
            s = endCol;
            inc = -1;
        }
       
        NoteRecord[] noteRecs;
        if (moveComments) {
            noteRecs = _helper.getInternalSheet().getNoteRecords();
        } else {
            noteRecs = NoteRecord.EMPTY_ARRAY;
        }

        final int maxrow = SpreadsheetVersion.EXCEL97.getLastRowIndex();
        final int maxcol = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
        final List<CellRangeAddress[]> shiftedRanges = BookHelper.shiftMergedRegion(this, 0, startCol, maxrow, endCol, n, true);
        _helper.getInternalSheet().getPageSettings().shiftColumnBreaks((short)startCol, (short)endCol, (short)n);

        // Fix up column width and comment if required
        if (moveComments || copyColWidth || resetOriginalColWidth) {
          final int defaultColumnWidth = getDefaultColumnWidth();
          for ( int colNum = s; colNum >= startCol && colNum <= endCol && colNum >= 0 && colNum <= maxcol; colNum += inc ) {
            final int newColNum = colNum + n;
            if (copyColWidth) {
                setColumnWidth(newColNum, getColumnWidth(colNum));
            }
            if (resetOriginalColWidth) {
                setColumnWidth(colNum, defaultColumnWidth);
            }
              // Move comments from the source column to the
              //  destination column. Note that comments can
              //  exist for cells which are null
              if(moveComments) {
                  for(int i=noteRecs.length-1; i>=0; i--) {
                      NoteRecord nr = noteRecs[i];
                      if (nr.getColumn() != colNum) {
                          continue;
                      }
                      HSSFComment comment = getCellComment(nr.getRow(), colNum);
                      if (comment != null) {
                         comment.setColumn(newColNum);
                      }
                  }
              }
          }
        }

        //handle inserted columns
        if (srcCol >= 0) {
          final int col2 = Math.min(startCol + n - 1, maxcol);
          for (int col = startCol; col <= col2 ; ++col) {
            //copy the column width
            setColumnWidth(col, colWidth);
            if (colStyle != null) {
              setDefaultColumnStyle(col, BookHelper.copyFromStyleExceptBorder(getBook(), colStyle));
            }
          }
          if (cells != null) {
            for (Entry<Integer, Cell> cellEntry : cells.entrySet()) {
                final HSSFRow row = getRow(cellEntry.getKey().intValue());
                final Cell srcCell = cellEntry.getValue();
                final CellStyle srcStyle = srcCell.getCellStyle();
              for (int col = startCol; col <= col2; ++col) {
                Cell dstCell = row.getCell(col);
                if (dstCell == null) {
                  dstCell = row.createCell(col);
                }
                dstCell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), srcStyle));
              }
            }
          }
        }
       
View Full Code Here

              if (colNum > maxColNum)
                maxColNum = colNum;
            }
           
            if (n > 0 && cells != null) {
               final Cell cell = row.getCell(srcCol);
               if (cell != null) {
                 cells.put(Integer.valueOf(rowNum), cell);
               }
            }
           
            row.shiftCells(startCol, endCol, n, clearRest);
        }
       
        if (endCol < 0) {
          endCol = maxColNum;
        }
        if (n > 0) {
          if (startCol > endCol) { //nothing to do
            return Collections.emptyList();
          }
        } else {
          if ((startCol + n) > endCol) { //nothing to do
            return Collections.emptyList();
          }
        }
       
        int s, inc;
        if (n < 0) {
            s = startCol;
            inc = 1;
        } else {
            s = endCol;
            inc = -1;
        }
       
        NoteRecord[] noteRecs;
        if (moveComments) {
            noteRecs = _helper.getInternalSheet().getNoteRecords();
        } else {
            noteRecs = NoteRecord.EMPTY_ARRAY;
        }

        final int maxrow = SpreadsheetVersion.EXCEL97.getLastRowIndex();
        final int maxcol = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
        final List<CellRangeAddress[]> shiftedRanges = BookHelper.shiftMergedRegion(this, tRow, startCol, bRow, endCol, n, true);
        final boolean wholeColumn = tRow == 0 && bRow == maxrow;
        if (wholeColumn) {
          _helper.getInternalSheet().getPageSettings().shiftColumnBreaks((short)startCol, (short)endCol, (short)n);
        }

        // Fix up column width and comment if required
        if (moveComments || copyColWidth || resetOriginalColWidth) {
          final int defaultColumnWidth = getDefaultColumnWidth();
          for ( int colNum = s; colNum >= startCol && colNum <= endCol && colNum >= 0 && colNum <= maxcol; colNum += inc ) {
            final int newColNum = colNum + n;
            if (wholeColumn) {
              if (copyColWidth) {
                  setColumnWidth(newColNum, getColumnWidth(colNum));
              }
              if (resetOriginalColWidth) {
                  setColumnWidth(colNum, defaultColumnWidth);
              }
            }
              // Move comments from the source column to the
              //  destination column. Note that comments can
              //  exist for cells which are null
              if(moveComments) {
                  for(int i=noteRecs.length-1; i>=0; i--) {
                      NoteRecord nr = noteRecs[i];
                      if (nr.getColumn() != colNum || nr.getRow() < tRow || nr.getRow() > bRow) { //not in range
                          continue;
                      }
                      HSSFComment comment = getCellComment(nr.getRow(), colNum);
                      if (comment != null) {
                         comment.setColumn(newColNum);
                      }
                  }
              }
          }
        }

        //handle inserted columns
        if (srcCol >= 0) {
          final int col2 = Math.min(startCol + n - 1, maxcol);
          if (wholeColumn) {
            for (int col = startCol; col <= col2 ; ++col) {
              //copy the column width
              setColumnWidth(col, colWidth);
              setDefaultColumnStyle(col, BookHelper.copyFromStyleExceptBorder(getBook(), colStyle));
            }
          }
          if (cells != null) {
            for (Entry<Integer, Cell> cellEntry : cells.entrySet()) {
                final HSSFRow row = getRow(cellEntry.getKey().intValue());
                final Cell srcCell = cellEntry.getValue();
                final CellStyle srcStyle = srcCell.getCellStyle();
              for (int col = startCol; col <= col2 ; ++col) {
                Cell dstCell = row.getCell(col);
                if (dstCell == null) {
                  dstCell = row.createCell(col);
                }
                dstCell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), srcStyle));
              }
            }
          }
        }
       
View Full Code Here

              row.setRowStyle((HSSFCellStyle)BookHelper.copyFromStyleExceptBorder(getBook(), srcStyle));
            }
                if (srcCells != null) {
              for(Entry<Integer, Cell> cellEntry : srcCells.entrySet()) {
                final int colnum = cellEntry.getKey().intValue();
                final Cell srcCell = cellEntry.getValue();
                final CellStyle cellStyle = srcCell.getCellStyle();
                Cell dstCell = row.getCell(colnum);
                if (dstCell == null) {
                  dstCell = row.createCell(colnum);
                }
                dstCell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), cellStyle));
              }
                }
          }
        }
       
View Full Code Here

    //20100701, henrichen@zkoss.org: remove cells of the row between specified left column and right column
    private void removeCells(Row row, int lCol, int rCol) {
      final int startCol = Math.max(row.getFirstCellNum(), lCol);
      final int endCol = Math.min(row.getLastCellNum(), rCol);
    for(int col = startCol; col <= endCol; ++col) {
      final Cell cell = row.getCell(col);
      if (cell != null) {
        row.removeCell(cell);
      }
    }
    }
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.