/** * Create a new CellAddress object. * * @param address a cell address in A1 format. Address may not contain sheet name or dollar signs. * (that is, address is not a cell reference. Use {@link #CellAddress(CellReference)} instead * if starting with a cell reference.) */ public CellAddress(String address) { int length = address.length(); int loc = 0; // step over column name chars until first digit for row number. for (; loc < length; loc++) { char ch = address.charAt(loc); if (Character.isDigit(ch)) { break; } } String sCol = address.substring(0, loc).toUpperCase(Locale.ROOT); String sRow = address.substring(loc); // FIXME: breaks if address contains a sheet name or dollar signs from an absolute CellReference this._row = Integer.parseInt(sRow) - 1; this._col = CellReference.convertColStringToIndex(sCol); }
/** * Create a new CellAddress object. * * @param reference a reference to a cell */ public CellAddress(CellReference reference) { this(reference.getRow(), reference.getCol()); }
/** * Same as {@link #toString()} * * @return A1-style cell address string representation */ public String formatAsString() { return CellReference.convertNumToColString(this._col) + (this._row + 1); }