View | Details | Raw Unified | Return to bug 58253
Collapse All | Expand All

(-)src/java/org/apache/poi/ss/util/CellReference.java (-19 / +38 lines)
Lines 85-98 Link Here
85
	 * delimited and escaped as per normal syntax rules for formulas.
85
	 * delimited and escaped as per normal syntax rules for formulas.
86
	 */
86
	 */
87
	public CellReference(String cellRef) {
87
	public CellReference(String cellRef) {
88
      if(cellRef.endsWith("#REF!")) {
88
		if(cellRef.toUpperCase().endsWith("#REF!")) {
89
         throw new IllegalArgumentException("Cell reference invalid: " + cellRef);
89
			throw new IllegalArgumentException("Cell reference invalid: " + cellRef);
90
      }
90
		}
91
91
92
		String[] parts = separateRefParts(cellRef);
92
		CellRefParts parts = separateRefParts(cellRef);
93
		_sheetName = parts[0];
93
		_sheetName = parts.sheetName;
94
94
95
		String colRef = parts[1];
95
		String colRef = parts.colRef;
96
		_isColAbs = (colRef.length() > 0) && colRef.charAt(0) == '$';
96
		_isColAbs = (colRef.length() > 0) && colRef.charAt(0) == '$';
97
		if (_isColAbs) {
97
		if (_isColAbs) {
98
		  colRef = colRef.substring(1);
98
		  colRef = colRef.substring(1);
Lines 103-110 Link Here
103
		  _colIndex = convertColStringToIndex(colRef);
103
		  _colIndex = convertColStringToIndex(colRef);
104
		}
104
		}
105
105
106
		String rowRef=parts[2];
106
		String rowRef=parts.rowRef;
107
    _isRowAbs = (rowRef.length() > 0) && rowRef.charAt(0) == '$';
107
		_isRowAbs = (rowRef.length() > 0) && rowRef.charAt(0) == '$';
108
		if (_isRowAbs) {
108
		if (_isRowAbs) {
109
		  rowRef = rowRef.substring(1);
109
		  rowRef = rowRef.substring(1);
110
		}
110
		}
Lines 332-351 Link Here
332
		}
332
		}
333
		return rowNum <= ssVersion.getMaxRows();
333
		return rowNum <= ssVersion.getMaxRows();
334
	}
334
	}
335
	
336
	private static final class CellRefParts {
337
		final String sheetName;
338
		final String rowRef;
339
		final String colRef; 
340
		
341
		private CellRefParts(String sheetName, String rowRef, String colRef) {
342
			this.sheetName = sheetName;
343
			this.rowRef = rowRef;
344
			this.colRef = colRef;
345
		}
346
	}
335
347
336
	/**
348
	/**
337
	 * Separates the row from the columns and returns an array of three Strings.  The first element
349
	 * Separates the sheet name, row, and columns from a cell reference string.
338
	 * is the sheet name. Only the first element may be null.  The second element in is the column
350
	 * 
339
	 * name still in ALPHA-26 number format.  The third element is the row.
351
	 * @param reference is a string that identifies a cell within the sheet or workbook
352
	 * reference may not refer to a cell in an external workbook
353
	 * reference may be absolute or relative.
354
	 * @return String array of sheetName, column (in ALPHA-26 format), and row
355
	 * output column or row elements will contain absolute reference markers if they
356
	 * existed in the input reference.
340
	 */
357
	 */
341
	private static String[] separateRefParts(String reference) {
358
	private static CellRefParts separateRefParts(String reference) {
342
		int plingPos = reference.lastIndexOf(SHEET_NAME_DELIMITER);
359
		int plingPos = reference.lastIndexOf(SHEET_NAME_DELIMITER);
343
		String sheetName = parseSheetName(reference, plingPos);
360
		final String sheetName = parseSheetName(reference, plingPos);
361
		String row;
362
		String col;
344
		int start = plingPos+1;
363
		int start = plingPos+1;
345
364
346
		int length = reference.length();
365
		int length = reference.length();
347
366
348
349
		int loc = start;
367
		int loc = start;
350
		// skip initial dollars
368
		// skip initial dollars
351
		if (reference.charAt(loc)==ABSOLUTE_REFERENCE_MARKER) {
369
		if (reference.charAt(loc)==ABSOLUTE_REFERENCE_MARKER) {
Lines 358-368 Link Here
358
				break;
376
				break;
359
			}
377
			}
360
		}
378
		}
361
		return new String[] {
379
		
362
			sheetName,
380
		col = reference.substring(start,loc).toUpperCase();
363
			reference.substring(start,loc),
381
		row = reference.substring(loc);
364
			reference.substring(loc),
382
		CellRefParts cellRefParts = new CellRefParts(sheetName, row, col);
365
		};
383
		return cellRefParts;
366
	}
384
	}
367
385
368
	private static String parseSheetName(String reference, int indexOfSheetNameDelimiter) {
386
	private static String parseSheetName(String reference, int indexOfSheetNameDelimiter) {
Lines 471-476 Link Here
471
	 * This will not include any markers for absolute
489
	 * This will not include any markers for absolute
472
	 *  references, so use {@link #formatAsString()}
490
	 *  references, so use {@link #formatAsString()}
473
	 *  to properly turn references into strings.
491
	 *  to properly turn references into strings.
492
	 *  @return String array of { sheetName, rowString, colString }
474
	 */
493
	 */
475
	public String[] getCellRefParts() {
494
	public String[] getCellRefParts() {
476
		return new String[] {
495
		return new String[] {

Return to bug 58253