Package org.zkoss.poi.ss.usermodel

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


            final Row row = sheet.getRow(r);
            if (row != null) {
              for (int c = left; c <= right; ++c) {
                final Cell cell = row.getCell(c);
                if (cell != null) {
                  final CellStyle cs = cell.getCellStyle();
                  if (cs != null && cs.getLocked()) {
                    //as long as one is protected and locked, return true
                    return true;
                  }
                }
              }
View Full Code Here


  /**
   * Returns the {@link Font} of the current cell
   * @return  the {@link Font} of the current cell
   */
  public Font getFont() {
    CellStyle cs = getOrCreateCell().getCellStyle();
    return book.getFontAt((short)cs.getFontIndex());
  }
View Full Code Here

  /**
   * Copy the current cell's style setting, returns a new {@link CellStyle}
   * @return CellStyle
   */
  public CellStyle cloneCellStyle() {
    CellStyle newCellStyle = book.createCellStyle();
    newCellStyle.cloneStyleFrom(getOrCreateCell().getCellStyle());
    return newCellStyle;
  }
View Full Code Here

//              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);
                }
View Full Code Here

//              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);
                }
View Full Code Here

     */
    public List<CellRangeAddress[]> shiftColumnsOnly(int startCol, int endCol, int n,
            boolean copyColWidth, boolean resetOriginalColWidth, boolean moveComments, boolean clearRest, int copyOrigin) {
      //prepared inserting column format
      final int srcCol = n <= 0 ? -1 : copyOrigin == Range.FORMAT_RIGHTBELOW ? startCol : copyOrigin == Range.FORMAT_LEFTABOVE ? startCol - 1 : -1;
      final CellStyle colStyle = srcCol >= 0 ? getColumnStyle(srcCol) : null;
      final int colWidth = srcCol >= 0 ? getColumnWidth(srcCol) : -1;
      final Map<Integer, Cell> cells = srcCol >= 0 ? new HashMap<Integer, Cell>() : null;
     
      int maxColNum = -1;
        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
            XSSFRow row = (XSSFRow)it.next();
            int rowNum = row.getRowNum();
           
            if (endCol < 0) {
              final int colNum = row.getLastCellNum() - 1;
              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);
                }
View Full Code Here

     */
    public List<CellRangeAddress[]> shiftColumnsRange(int startCol, int endCol, int n, int tRow, int bRow,
            boolean copyColWidth, boolean resetOriginalColWidth, boolean moveComments, boolean clearRest, int copyOrigin) {
      //prepared inserting column format
      final int srcCol = n <= 0 ? -1 : copyOrigin == Range.FORMAT_RIGHTBELOW ? startCol : copyOrigin == Range.FORMAT_LEFTABOVE ? startCol - 1 : -1;
      final CellStyle colStyle = srcCol >= 0 ? getColumnStyle(srcCol) : null;
      final int colWidth = srcCol >= 0 ? getColumnWidth(srcCol) : -1;
      final Map<Integer, Cell> cells = srcCol >= 0 ? new HashMap<Integer, Cell>() : null;
     
      int startRow = Math.max(tRow, getFirstRowNum());
      int endRow = Math.min(bRow, getLastRowNum());
      int maxColNum = -1;
      if (startRow <= endRow) {
          for (Iterator<XSSFRow> it = getRows().subMap(startRow, endRow+1).values().iterator(); it.hasNext() ; ) {
              XSSFRow row = it.next();
              int rowNum = row.getRowNum();
             
              if (endCol < 0) {
                final int colNum = row.getLastCellNum() - 1;
                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);
                }
View Full Code Here

              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);
                }
View Full Code Here

     */
    public List<CellRangeAddress[]> shiftColumnsOnly(int startCol, int endCol, int n,
            boolean copyColWidth, boolean resetOriginalColWidth, boolean moveComments, boolean clearRest, int copyOrigin) {
      //prepared inserting column format
      final int srcCol = n <= 0 ? -1 : copyOrigin == Range.FORMAT_RIGHTBELOW ? startCol : copyOrigin == Range.FORMAT_LEFTABOVE ? startCol - 1 : -1;
      final CellStyle colStyle = srcCol >= 0 ? getColumnStyle(srcCol) : null;
      final int colWidth = srcCol >= 0 ? getColumnWidth(srcCol) : -1;
      final Map<Integer, Cell> cells = srcCol >= 0 ? new HashMap<Integer, Cell>() : null;
     
      int maxColNum = -1;
        for ( int rowNum = getFirstRowNum(), endRowNum = getLastRowNum(); rowNum <= endRowNum; ++rowNum ) {
            HSSFRow row = getRow( rowNum );
           
            if (row == null) continue;
           
            if (endCol < 0) {
              final int colNum = row.getLastCellNum() - 1;
              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);
                }
View Full Code Here

    public List<CellRangeAddress[]> shiftColumnsRange(int startCol, int endCol, int n, int tRow, int bRow,
            boolean copyColWidth, boolean resetOriginalColWidth, boolean moveComments, boolean clearRest, int copyOrigin) {
     
      //prepared inserting column format
      final int srcCol = n <= 0 ? -1 : copyOrigin == Range.FORMAT_RIGHTBELOW ? startCol : copyOrigin == Range.FORMAT_LEFTABOVE ? startCol - 1 : -1;
      final CellStyle colStyle = srcCol >= 0 ? getColumnStyle(srcCol) : null;
      final int colWidth = srcCol >= 0 ? getColumnWidth(srcCol) : -1;
      final Map<Integer, Cell> cells = srcCol >= 0 ? new HashMap<Integer, Cell>() : null;
     
      int startRow = Math.max(tRow, getFirstRowNum());
      int endRow = Math.min(bRow, getLastRowNum());
      int maxColNum = -1;
        for ( int rowNum = startRow, endRowNum = endRow; rowNum <= endRowNum; ++rowNum ) {
            HSSFRow row = getRow( rowNum );
           
            if (row == null) continue;
           
            if (endCol < 0) {
              final int colNum = row.getLastCellNum() - 1;
              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);
                }
View Full Code Here

TOP

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

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.