/** * Returns the sheet this cell belongs to * * @return the sheet this cell belongs to */ @Override public XSSFSheet getSheet() { return getRow().getSheet(); }
/** * Compares two <code>XSSFRow</code> objects. Two rows are equal if they belong to the same worksheet and * their row indexes are equal. * * @param other the <code>XSSFRow</code> to be compared. * @return <ul> * <li> * the value <code>0</code> if the row number of this <code>XSSFRow</code> is * equal to the row number of the argument <code>XSSFRow</code> * </li> * <li> * a value less than <code>0</code> if the row number of this this <code>XSSFRow</code> is * numerically less than the row number of the argument <code>XSSFRow</code> * </li> * <li> * a value greater than <code>0</code> if the row number of this this <code>XSSFRow</code> is * numerically greater than the row number of the argument <code>XSSFRow</code> * </li> * </ul> * @throws IllegalArgumentException if the argument row belongs to a different worksheet */ @Override public int compareTo(XSSFRow 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); }
/** * The purpose of this method is to validate the cell state prior to modification * * @see #notifyArrayFormulaChanging() */ void notifyArrayFormulaChanging(String msg){ if(isPartOfArrayFormulaGroup()){ CellRangeAddress cra = getArrayFormulaRange(); if(cra.getNumberOfCells() > 1) { throw new IllegalStateException(msg); } //un-register the single-cell array formula from the parent XSSFSheet getRow().getSheet().removeArrayFormula(this); } }
/** * Returns the whole-row cell style. Most rows won't * have one of these, so will return null. Call * {@link #isFormatted()} to check first. */ @Override public XSSFCellStyle getRowStyle() { if(!isFormatted()) { return null; } StylesTable stylesSource = getSheet().getWorkbook().getStylesSource(); if(stylesSource.getNumCellStyles() > 0) { return stylesSource.getStyleAt((int)_row.getS()); } else { return null; } }
/** * Construct a XSSFCell. * * @param row the parent row. * @param cell the xml bean containing information about the cell. */ protected XSSFCell(XSSFRow row, CTCell cell) { _cell = cell; _row = row; if (cell.getR() != null) { _cellNum = new CellReference(cell.getR()).getCol(); } else { int prevNum = row.getLastCellNum(); if(prevNum != -1){ _cellNum = row.getCell(prevNum-1, MissingCellPolicy.RETURN_NULL_AND_BLANK).getColumnIndex() + 1; } } _sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource(); _stylesSource = row.getSheet().getWorkbook().getStylesSource(); }
private void setFormula(String formula, FormulaType formulaType) { XSSFWorkbook wb = _row.getSheet().getWorkbook(); if (formula == null) { wb.onDeleteFormula(this); if (_cell.isSetF()) { _row.getSheet().onDeleteFormula(this, null); _cell.unsetF(); f.setStringValue(formula); if(f.getT() == STCellFormulaType.SHARED){ getRow().getSheet().onReadCell(this);
/** * Applies a whole-row cell styling to the row. * If the value is null then the style information is removed, * causing the cell to used the default workbook style. */ @Override public void setRowStyle(CellStyle style) { if(style == null) { if(_row.isSetS()) { _row.unsetS(); _row.unsetCustomFormat(); } } else { StylesTable styleSource = getSheet().getWorkbook().getStylesSource(); XSSFCellStyle xStyle = (XSSFCellStyle)style; xStyle.verifyBelongsToStylesSource(styleSource); long idx = styleSource.putStyle(xStyle); _row.setS(idx); _row.setCustomFormat(true); } }
XSSFSheet sheet = row.getSheet(); for (Cell c : row) { XSSFCell cell = (XSSFCell) c;
int index = 0; final Set<Integer> indices = new HashSet<>(); for (CellRangeAddress destRegion : getSheet().getMergedRegions()) { if (destRowNum == destRegion.getFirstRow() && destRowNum == destRegion.getLastRow()) { indices.add(index); getSheet().removeMergedRegions(indices); destRegion.setFirstRow(destRowNum); destRegion.setLastRow(destRowNum); getSheet().addMergedRegion(destRegion);
_row.getSheet().onDeleteFormula(this, evalWb);
/** * Returns the sheet this cell belongs to * * @return the sheet this cell belongs to */ @Override public XSSFSheet getSheet() { return getRow().getSheet(); }
/** * Returns the sheet this cell belongs to * * @return the sheet this cell belongs to */ public XSSFSheet getSheet() { return getRow().getSheet(); }
/** * The purpose of this method is to validate the cell state prior to modification * * @see #notifyArrayFormulaChanging() */ void notifyArrayFormulaChanging(String msg){ if(isPartOfArrayFormulaGroup()){ CellRangeAddress cra = getArrayFormulaRange(); if(cra.getNumberOfCells() > 1) { throw new IllegalStateException(msg); } //un-register the single-cell array formula from the parent XSSFSheet getRow().getSheet().removeArrayFormula(this); } }
/** * The purpose of this method is to validate the cell state prior to modification * * @see #notifyArrayFormulaChanging() */ void notifyArrayFormulaChanging(String msg){ if(isPartOfArrayFormulaGroup()){ CellRangeAddress cra = getArrayFormulaRange(); if(cra.getNumberOfCells() > 1) { throw new IllegalStateException(msg); } //un-register the single-cell array formula from the parent XSSFSheet getRow().getSheet().removeArrayFormula(this); } }
/** * Construct a XSSFCell. * * @param row the parent row. * @param cell the xml bean containing information about the cell. */ protected XSSFCell(XSSFRow row, CTCell cell) { _cell = cell; _row = row; if (cell.getR() != null) { _cellNum = new CellReference(cell.getR()).getCol(); } _sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource(); _stylesSource = row.getSheet().getWorkbook().getStylesSource(); }
public Node parseRows(Node top, XSSFRow row) { int len = row.getCTRow().getCArray().length; Node rowNode = len == 0 ? createEmptyRow(sheet, getCurrentRow()) : createRowNode(row.getSheet(), row); for (int i = 0; i < row.getLastCellNum(); i++) { XSSFCell cell = row.getCell(i); Node cellNode; if (cell == null) { cellNode = createEmtyCell(sheet, row.getCell(i, Row.CREATE_NULL_AS_BLANK)); } else { cellNode = createCellNode(row.getSheet(), cell, cell.getColumnIndex(), CellExpressionParser.parse(cell), rowNode); } rowNode.getChildren().add(cellNode); } return rowNode; }
/** * Returns the whole-row cell style. Most rows won't * have one of these, so will return null. Call * {@link #isFormatted()} to check first. */ public XSSFCellStyle getRowStyle() { if(!isFormatted()) return null; StylesTable stylesSource = getSheet().getWorkbook().getStylesSource(); if(stylesSource.getNumCellStyles() > 0) { return stylesSource.getStyleAt((int)_row.getS()); } else { return null; } }
private void setFormula(String formula, int formulaType) { XSSFWorkbook wb = _row.getSheet().getWorkbook(); if (formula == null) { wb.onDeleteFormula(this); if(_cell.isSetF()) _cell.unsetF(); return; } XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb); //validate through the FormulaParser FormulaParser.parse(formula, fpb, formulaType, wb.getSheetIndex(getSheet())); CTCellFormula f = CTCellFormula.Factory.newInstance(); f.setStringValue(formula); _cell.setF(f); if(_cell.isSetV()) _cell.unsetV(); }