/** * Create an area ref from a string representation. Sheet names containing special Chars should be * delimited and escaped as per normal syntax rules for formulas.<br/> * The area reference must be contiguous (i.e. represent a single rectangle, not a Union of rectangles) */ public AreaReference(String reference, SpreadsheetVersion version) { _version = (null != version) ? version : DEFAULT_SPREADSHEET_VERSION; if (!IsContiguous(reference)) { throw new ArgumentException( "References passed to the AreaReference must be contiguous, " + "use generateContiguous(ref) if you have non-contiguous references"); } String[] parts = SeparateAreaRefs(reference); String part0 = parts[0]; if (parts.Length == 1) { // TODO - probably shouldn't initialize area ref when text is really a cell ref // Need to fix some named range stuff to get rid of this _firstCell = new CellReference(part0); _lastCell = _firstCell; _isSingleCell = true; return; } if (parts.Length != 2) { throw new ArgumentException("Bad area ref '" + reference + "'"); } String part1 = parts[1]; if (IsPlainColumn(part0)) { if (!IsPlainColumn(part1)) { throw new Exception("Bad area ref '" + reference + "'"); } // Special handling for whole-column references // Represented internally as x$1 to x$65536 // which is the maximum range of rows bool firstIsAbs = CellReference.IsPartAbsolute(part0); bool lastIsAbs = CellReference.IsPartAbsolute(part1); int col0 = CellReference.ConvertColStringToIndex(part0); int col1 = CellReference.ConvertColStringToIndex(part1); _firstCell = new CellReference(0, col0, true, firstIsAbs); _lastCell = new CellReference(0xFFFF, col1, true, lastIsAbs); _isSingleCell = false; // TODO - whole row refs } else { _firstCell = new CellReference(part0); _lastCell = new CellReference(part1); _isSingleCell = part0.Equals(part1); } }
/** * 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[loc]; if (Char.IsDigit(ch)) { break; } } String sCol = address.Substring(0, loc).ToUpper(); String sRow = address.Substring(loc); // FIXME: breaks if Address Contains a sheet name or dollar signs from an absolute CellReference this._row = int.Parse(sRow) - 1; this._col = CellReference.ConvertColStringToIndex(sCol); }