static SXSSFCell newSXSSFCell(SXSSFRow row, int index) { return row.createCell(index); }
/** * Get the cell representing a given column (logical cell) 0-based. * If cell is missing or blank, uses the workbook's MissingCellPolicy * to determine the return value. * * @param cellnum 0 based column number * @return Cell representing that column or null if undefined. * @see #getCell(int, org.apache.poi.ss.usermodel.Row.MissingCellPolicy) * @throws RuntimeException if cellnum is out of bounds */ @Override public SXSSFCell getCell(int cellnum) { MissingCellPolicy policy = _sheet.getWorkbook().getMissingCellPolicy(); return getCell(cellnum, policy); }
/** * Write a row to the file * * @param rownum 0-based row number * @param row a row * * @throws IOException If an I/O error occurs */ public void writeRow(int rownum, SXSSFRow row) throws IOException { if (_numberOfFlushedRows == 0) _lowestIndexOfFlushedRows = rownum; _numberLastFlushedRow = Math.max(rownum, _numberLastFlushedRow); _numberOfCellsOfLastFlushedRow = row.getLastCellNum(); _numberOfFlushedRows++; beginRow(rownum, row); Iterator<Cell> cells = row.allCellsIterator(); int columnIndex = 0; while (cells.hasNext()) { writeCell(columnIndex++, cells.next()); } endRow(); }
/** * Returns the cell at the given (0 based) index, with the specified {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy} * * @return the cell at the given (0 based) index * @throws IllegalArgumentException if cellnum < 0 or the specified MissingCellPolicy is invalid */ @Override public SXSSFCell getCell(int cellnum, MissingCellPolicy policy) { checkBounds(cellnum); final SXSSFCell cell = _cells.get(cellnum); switch (policy) { case RETURN_NULL_AND_BLANK: return cell; case RETURN_BLANK_AS_NULL: boolean isBlank = (cell != null && cell.getCellType() == CellType.BLANK); return (isBlank) ? null : cell; case CREATE_NULL_AS_BLANK: return (cell == null) ? createCell(cellnum, CellType.BLANK) : cell; default: throw new IllegalArgumentException("Illegal policy " + policy); } }
targetRow.setHeight(sourceRow.getHeight()); SXSSFCell targetCell = (SXSSFCell) targetRow.getCell(i); targetCell = (SXSSFCell) targetRow.createCell(i);
Cell cell = getCell(cellnum); if(policy == RETURN_NULL_AND_BLANK) return createCell(cellnum, Cell.CELL_TYPE_BLANK);
currentRow=currentSheet.createRow(currentCA.getRow()); SXSSFCell currentCell = currentRow.getCell(currentCA.getColumn()); if ((currentCell!=null)) { // cell already exists and no template loaded ? => throw exception throw new OfficeWriterException("Invalid cell specification: cell already exists at "+currentCA); currentCell=currentRow.createCell(currentCA.getColumn()); anchor.setCol1(currentCell.getColumnIndex()); anchor.setCol2(currentCell.getColumnIndex()+this.howc.getCommentWidth()); anchor.setRow1(currentRow.getRowNum()); anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
/** * 初始化第一行的属性 * * @param workbook * @param propertyList * @param sheetName * @return */ private SXSSFSheet generateHeader(SXSSFWorkbook workbook, List<ExcelPropertyEntity> propertyList, String sheetName) { SXSSFSheet sheet = workbook.createSheet(sheetName); SXSSFRow headerRow = sheet.createRow(0); headerRow.setHeight((short) 600); CellStyle headCellStyle = getHeaderCellStyle(workbook); for (int i = 0; i < propertyList.size(); i++) { SXSSFCell cell = headerRow.createCell(i); cell.setCellStyle(headCellStyle); cell.setCellValue(propertyList.get(i).getColumnName()); calculateColumWidth(cell, i); } return sheet; }
/** * Returns column index of this cell * * @return zero-based column index of a column in a sheet. */ @Override public int getColumnIndex() { return _row.getCellIndex(this); }
/** * Returns row index of a row in the sheet that contains this cell * * @return zero-based row index of a row in the sheet that contains this cell */ @Override public int getRowIndex() { return _row.getRowNum(); }
/** * Use this to create new cells within the row and return it. * <p> * The cell that is returned is a {@link CellType#BLANK}. The type can be changed * either through calling setCellValue or setCellType. * * @param column - the column number this cell represents * @return Cell a high level representation of the created cell. * @throws IllegalArgumentException if columnIndex < 0 or greater than a maximum number of supported columns * (255 for *.xls, 1048576 for *.xlsx) */ @Override public SXSSFCell createCell(int column, CellType type) { checkBounds(column); SXSSFCell cell = new SXSSFCell(this, type); _cells.put(column, cell); return cell; }
SXSSFRow newRow = new SXSSFRow(this); _rows.put(rownum, newRow); allFlushed = false;
protected void autoSizeColumns(SXSSFSheet sheet) { short lastColumn = sheet.getRow(sheet.getLastRowNum()).getLastCellNum(); // Skip column with Test name and ID column for (int i = FIRST_COLUMN + 1; i < lastColumn; i++) { sheet.autoSizeColumn(i); } }
/** * Returns the cell at the given (0 based) index, with the specified {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy} * * @return the cell at the given (0 based) index * @throws IllegalArgumentException if cellnum < 0 or the specified MissingCellPolicy is invalid */ @Override public SXSSFCell getCell(int cellnum, MissingCellPolicy policy) { checkBounds(cellnum); final SXSSFCell cell = _cells.get(cellnum); switch (policy) { case RETURN_NULL_AND_BLANK: return cell; case RETURN_BLANK_AS_NULL: boolean isBlank = (cell != null && cell.getCellType() == CellType.BLANK); return (isBlank) ? null : cell; case CREATE_NULL_AS_BLANK: return (cell == null) ? createCell(cellnum, CellType.BLANK) : cell; default: throw new IllegalArgumentException("Illegal policy " + policy); } }
/** * Compares two <code>SXSSFRow</code> objects. Two rows are equal if they belong to the same worksheet and * their row indexes are equal. * * @param other the <code>SXSSFRow</code> to be compared. * @return <ul> * <li> * the value <code>0</code> if the row number of this <code>SXSSFRow</code> is * equal to the row number of the argument <code>SXSSFRow</code> * </li> * <li> * a value less than <code>0</code> if the row number of this this <code>SXSSFRow</code> is * numerically less than the row number of the argument <code>SXSSFRow</code> * </li> * <li> * a value greater than <code>0</code> if the row number of this this <code>SXSSFRow</code> is * numerically greater than the row number of the argument <code>SXSSFRow</code> * </li> * </ul> * @throws IllegalArgumentException if the argument row belongs to a different worksheet */ @Override public int compareTo(SXSSFRow other) { if (this.getSheet() != other.getSheet()) { throw new IllegalArgumentException("The compared rows must belong to the same sheet"); } int thisRow = this.getRowNum(); int otherRow = other.getRowNum(); return Integer.compare(thisRow, otherRow); }
/** * Remove the Cell from this row. * * @param cell the cell to remove */ @Override public void removeCell(Cell cell) { int index = getCellIndex((SXSSFCell) cell); _cells.remove(index); }
/** * Returns row index of a row in the sheet that contains this cell * * @return zero-based row index of a row in the sheet that contains this cell */ @Override public int getRowIndex() { return _row.getRowNum(); }
/** * Use this to create new cells within the row and return it. * <p> * The cell that is returned is a {@link CellType#BLANK}. The type can be changed * either through calling setCellValue or setCellType. * * @param column - the column number this cell represents * @return Cell a high level representation of the created cell. * @throws IllegalArgumentException if columnIndex < 0 or greater than a maximum number of supported columns * (255 for *.xls, 1048576 for *.xlsx) */ @Override public SXSSFCell createCell(int column, CellType type) { checkBounds(column); SXSSFCell cell = new SXSSFCell(this, type); _cells.put(column, cell); return cell; }
SXSSFRow newRow=new SXSSFRow(this,initialAllocationSize); _rows.put(new Integer(rownum),newRow); if(_randomAccessWindowSize>=0&&_rows.size()>_randomAccessWindowSize)