/** * Separates the sheet name, row, and columns from a cell reference string. * * @param reference is a string that identifies a cell within the sheet or workbook * reference may not refer to a cell in an external workbook * reference may be absolute or relative. * @return String array of sheetName, column (in ALPHA-26 format), and row * output column or row elements will contain absolute reference markers if they * existed in the input reference. */ private static CellRefParts separateRefParts(String reference) { int plingPos = reference.lastIndexOf(SHEET_NAME_DELIMITER); final String sheetName = parseSheetName(reference, plingPos); String cell = reference.substring(plingPos+1).toUpperCase(Locale.ROOT); Matcher matcher = CELL_REF_PATTERN.matcher(cell); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid CellReference: " + reference); } String col = matcher.group(1); String row = matcher.group(2); return new CellRefParts(sheetName, row, col); }
/** * Separates the row from the columns and returns an array of three Strings. The first element * is the sheet name. Only the first element may be null. The second element in is the column * name still in ALPHA-26 number format. The third element is the row. */ private static String[] separateRefParts(String reference) { int plingPos = reference.lastIndexOf(SHEET_NAME_DELIMITER); String sheetName = parseSheetName(reference, plingPos); int start = plingPos+1; int length = reference.length(); int loc = start; // skip initial dollars if (reference.charAt(loc)==ABSOLUTE_REFERENCE_MARKER) { loc++; } // step over column name chars until first digit (or dollars) for row number. for (; loc < length; loc++) { char ch = reference.charAt(loc); if (Character.isDigit(ch) || ch == ABSOLUTE_REFERENCE_MARKER) { break; } } return new String[] { sheetName, reference.substring(start,loc), reference.substring(loc), }; }
/** * Separates the row from the columns and returns an array of three Strings. The first element * is the sheet name. Only the first element may be null. The second element in is the column * name still in ALPHA-26 number format. The third element is the row. */ private static String[] separateRefParts(String reference) { int plingPos = reference.lastIndexOf(SHEET_NAME_DELIMITER); String sheetName = parseSheetName(reference, plingPos); int start = plingPos+1; int length = reference.length(); int loc = start; // skip initial dollars if (reference.charAt(loc)==ABSOLUTE_REFERENCE_MARKER) { loc++; } // step over column name chars until first digit (or dollars) for row number. for (; loc < length; loc++) { char ch = reference.charAt(loc); if (Character.isDigit(ch) || ch == ABSOLUTE_REFERENCE_MARKER) { break; } } return new String[] { sheetName, reference.substring(start,loc), reference.substring(loc), }; }
/** * Separates the sheet name, row, and columns from a cell reference string. * * @param reference is a string that identifies a cell within the sheet or workbook * reference may not refer to a cell in an external workbook * reference may be absolute or relative. * @return String array of sheetName, column (in ALPHA-26 format), and row * output column or row elements will contain absolute reference markers if they * existed in the input reference. */ private static CellRefParts separateRefParts(String reference) { int plingPos = reference.lastIndexOf(SHEET_NAME_DELIMITER); final String sheetName = parseSheetName(reference, plingPos); String cell = reference.substring(plingPos+1).toUpperCase(Locale.ROOT); Matcher matcher = CELL_REF_PATTERN.matcher(cell); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid CellReference: " + reference); } String col = matcher.group(1); String row = matcher.group(2); return new CellRefParts(sheetName, row, col); }