/** * Create a new CellAddress object. * * @param reference a reference to a cell */ public CellAddress(CellReference reference) { this(reference.getRow(), reference.getCol()); }
/** * Return the row of the first cell that contains the hyperlink * * @return the 0-based row of the cell that contains the hyperlink */ @Override public int getFirstRow() { return buildCellReference().getRow(); }
/** * Return the row of the last cell that contains the hyperlink * * @return the 0-based row of the last cell that contains the hyperlink */ @Override public int getLastRow() { return buildCellReference().getRow(); }
/** * @since 3.15 beta 2 */ public int getStartRowIndex() { return getStartCellReference().getRow(); }
/** * @since 3.15 beta 2 */ public int getEndRowIndex() { return getEndCellReference().getRow(); }
private Integer getKeyForCache(final CellReference cellRef) { // The HSSF has a max of 2^16 rows and 2^8 cols return ((cellRef.getCol()+1)<<16 | cellRef.getRow()); }
public int getOffsetRows() { return target.getRow() - region.getFirstRow(); }
Sheet sheet = workbook.getSheet("MyInterestingSheet"); CellReference ref = new CellReference("B12"); Row r = sheet.getRow(ref.getRow()); if (r != null) { Cell c = r.getCell(ref.getCol()); }
/** * Is the reference for a whole-column reference, * such as C:C or D:G ? */ public static boolean isWholeColumnReference(SpreadsheetVersion version, CellReference topLeft, CellReference botRight) { if (null == version) { version = DEFAULT_SPREADSHEET_VERSION; // how the code used to behave. } // These are represented as something like // C$1:C$65535 or D$1:F$0 // i.e. absolute from 1st row to 0th one return (topLeft.getRow() == 0 && topLeft.isRowAbsolute() && botRight.getRow() == version.getLastRowIndex() && botRight.isRowAbsolute()); } public boolean isWholeColumnReference() {
/** * Determines if the given {@link CellReference} lies within the bounds * of this range. * <p>NOTE: It is up to the caller to ensure the reference is * for the correct sheet, since this instance doesn't have a sheet reference. * * @param ref the CellReference to check * @return True if the reference lies within the bounds, false otherwise. * @see #intersects(CellRangeAddressBase) for checking if two ranges overlap */ public boolean isInRange(CellReference ref) { return isInRange(ref.getRow(), ref.getCol()); }
public void add(FormulaRecordAggregate agg) { if (_numberOfFormulas == 0) { if (_firstCell.getRow() != agg.getRow() || _firstCell.getCol() != agg.getColumn()) { throw new IllegalStateException("shared formula coding error: "+_firstCell.getCol()+'/'+_firstCell.getRow()+" != "+agg.getColumn()+'/'+agg.getRow()); } } if (_numberOfFormulas >= _frAggs.length) { throw new RuntimeException("Too many formula records for shared formula group"); } _frAggs[_numberOfFormulas++] = agg; }
/** * The top row in the visible view when the sheet is * first viewed after opening it in a viewer * * @return integer indicating the rownum (0 based) of the top row */ @Override public short getTopRow() { final CTSheetView dsv = getDefaultSheetView(false); final String cellRef = (dsv == null) ? null : dsv.getTopLeftCell(); if(cellRef == null) { return 0; } return (short) new CellReference(cellRef).getRow(); }
/** * @param reference * @return the cell the refernce points to */ private Cell getCellFromReference( String reference ) { CellReference cellRef = new CellReference( reference ); String sheetName = cellRef.getSheetName(); Sheet sheet = data.sheet; if ( !Utils.isEmpty( sheetName ) ) { sheet = data.wb.getSheet( sheetName ); } if ( sheet == null ) { return null; } // reference is assumed to be absolute Row xlsRow = sheet.getRow( cellRef.getRow() ); if ( xlsRow == null ) { return null; } Cell styleCell = xlsRow.getCell( cellRef.getCol() ); return styleCell; }
public boolean isPartOfArrayFormula() { if (_sharedFormulaRecord != null) { return false; } CellReference expRef = _formulaRecord.getFormula().getExpReference(); ArrayRecord arec = expRef == null ? null : _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol()); return arec != null; }
private ValueEval evaluate(String formula, CellReference target, CellRangeAddressBase region, FormulaType formulaType) { final String sheetName = target == null ? null : target.getSheetName(); if (sheetName == null) throw new IllegalArgumentException("Sheet name is required"); final int sheetIndex = getWorkbook().getSheetIndex(sheetName); Ptg[] ptgs = FormulaParser.parse(formula, (FormulaParsingWorkbook) getWorkbook(), formulaType, sheetIndex, target.getRow()); adjustRegionRelativeReference(ptgs, target, region); final OperationEvaluationContext ec = new OperationEvaluationContext(this, getWorkbook(), sheetIndex, target.getRow(), target.getCol(), new EvaluationTracker(_cache), formulaType.isSingleValue()); return evaluateNameFormula(ptgs, ec); }
public SharedFormulaGroup(SharedFormulaRecord sfr, CellReference firstCell) { if (!sfr.isInRange(firstCell.getRow(), firstCell.getCol())) { throw new IllegalArgumentException("First formula cell " + firstCell.formatAsString() + " is not shared formula range " + sfr.getRange() + "."); } _sfr = sfr; _firstCell = firstCell; int width = sfr.getLastColumn() - sfr.getFirstColumn() + 1; int height = sfr.getLastRow() - sfr.getFirstRow() + 1; _frAggs = new FormulaRecordAggregate[width * height]; _numberOfFormulas = 0; }
public CellRangeAddress getArrayFormulaRange() { if (_sharedFormulaRecord != null) { throw new IllegalStateException("not an array formula cell."); } CellReference expRef = _formulaRecord.getFormula().getExpReference(); if (expRef == null) { throw new IllegalStateException("not an array formula cell."); } ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol()); if (arec == null) { throw new IllegalStateException("ArrayRecord was not found for the locator " + expRef.formatAsString()); } CellRangeAddress8Bit a = arec.getRange(); return new CellRangeAddress(a.getFirstRow(), a.getLastRow(), a.getFirstColumn(),a.getLastColumn()); }
public Ptg[] getFormulaTokens() { if (_sharedFormulaRecord != null) { return _sharedFormulaRecord.getFormulaTokens(_formulaRecord); } CellReference expRef = _formulaRecord.getFormula().getExpReference(); if (expRef != null) { ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol()); return arec.getFormulaTokens(); } return _formulaRecord.getParsedExpression(); }
protected RefPtgBase(CellReference c) { setRow(c.getRow()); setColumn(c.getCol()); setColRelative(!c.isColAbsolute()); setRowRelative(!c.isRowAbsolute()); }
protected AreaPtgBase(AreaReference ar) { CellReference firstCell = ar.getFirstCell(); CellReference lastCell = ar.getLastCell(); setFirstRow(firstCell.getRow()); setFirstColumn(firstCell.getCol() == -1 ? 0 : firstCell.getCol()); setLastRow(lastCell.getRow()); setLastColumn(lastCell.getCol() == -1 ? 0xFF : lastCell.getCol()); setFirstColRelative(!firstCell.isColAbsolute()); setLastColRelative(!lastCell.isColAbsolute()); setFirstRowRelative(!firstCell.isRowAbsolute()); setLastRowRelative(!lastCell.isRowAbsolute()); }