/** * Fired when the document is written to an output stream. * * @see org.apache.poi.xssf.usermodel.XSSFSheet#write(java.io.OutputStream) () */ protected void onDocumentWrite() { // check if cells in the CTRow are ordered boolean isOrdered = true; if (_row.sizeOfCArray() != _cells.size()) isOrdered = false; else { int i = 0; CTCell[] xcell = _row.getCArray(); for (XSSFCell cell : _cells.values()) { CTCell c1 = cell.getCTCell(); CTCell c2 = xcell[i++]; String r1 = c1.getR(); String r2 = c2.getR(); if (!(r1 == null ? r2 == null : r1.equals(r2))) { isOrdered = false; break; } } } if (!isOrdered) { CTCell[] cArray = new CTCell[_cells.size()]; int i = 0; for (XSSFCell c : _cells.values()) { cArray[i++] = c.getCTCell(); } _row.setCArray(cArray); } }
/** * Set the row number of this row. * * @param rowIndex the row number (0-based) * @throws IllegalArgumentException if rowNum < 0 or greater than 1048575 */ public void setRowNum(int rowIndex) { int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex(); if (rowIndex < 0 || rowIndex > maxrow) { throw new IllegalArgumentException( "Invalid row number (" + rowIndex + ") outside allowable range (0.." + maxrow + ")"); } _row.setR(rowIndex + 1); }
/** * Construct a XSSFRow. * * @param row the xml bean containing all cell definitions for this row. * @param sheet the parent sheet. */ protected XSSFRow(CTRow row, XSSFSheet sheet) { _row = row; _sheet = sheet; _cells = new TreeMap<Integer, XSSFCell>(); for (CTCell c : row.getCArray()) { XSSFCell cell = new XSSFCell(this, c); _cells.put(cell.getColumnIndex(), cell); sheet.onReadCell(cell); } }
/** * Set the height in "twips" or 1/20th of a point. * * @param height the height in "twips" or 1/20th of a point. <code>-1</code> resets to the default * height */ public void setHeight(short height) { if (height == -1) { if (_row.isSetHt()) _row.unsetHt(); if (_row.isSetCustomHeight()) _row.unsetCustomHeight(); } else { _row.setHt((double) height / 20); _row.setCustomHeight(true); } }
/** * Use this to create new cells within the row and return it. * * @param columnIndex - the column number this cell represents * @param type - the cell's data type * @return XSSFCell a high level representation of the created cell. * @throws IllegalArgumentException if the specified cell type is invalid, columnIndex < 0 or * greater than 16384, the maximum number of columns supported by the SpreadsheetML format * (.xlsx) * @see Cell#CELL_TYPE_BLANK * @see Cell#CELL_TYPE_BOOLEAN * @see Cell#CELL_TYPE_ERROR * @see Cell#CELL_TYPE_FORMULA * @see Cell#CELL_TYPE_NUMERIC * @see Cell#CELL_TYPE_STRING */ public XSSFCell createCell(int columnIndex, int type) { CTCell ctCell; XSSFCell prev = _cells.get(columnIndex); if (prev != null) { ctCell = prev.getCTCell(); ctCell.set(CTCell.Factory.newInstance()); } else { ctCell = _row.addNewC(); } XSSFCell xcell = new XSSFCell(this, ctCell); xcell.setCellNum(columnIndex); if (type != Cell.CELL_TYPE_BLANK) { xcell.setCellType(type); } _cells.put(columnIndex, xcell); return xcell; }
/** @return formatted xml representation of this row */ @Override public String toString() { return _row.toString(); }
/** * Get row number this row represents * * @return the row number (0 based) */ public int getRowNum() { return (int) (_row.getR() - 1); }