Package org.jxls.util
Class CellRefUtil
java.lang.Object
org.jxls.util.CellRefUtil
This is a class to convert Excel cell names to (sheet, row, col) representations and vice versa.
The current code is taken from Apache POI CellReference class ( http://poi.apache.org/apidocs/org/apache/poi/ss/util/CellReference.html ).
- Author:
- Leonid Vysochyn
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThe character ($) that signifies a row or column value is absolute instead of relativestatic final charThe character (!) that separates sheet names from cell references -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendFormat(StringBuilder out, String rawSheetName) static booleancellReferenceIsWithinRange(String colStr, String rowStr, int lastColumnIndex, int lastRowIndex) Used to decide whether a name of the form "[A-Z]*[0-9]*" that appears in a formula can be interpreted as a cell reference.static inttakes in a column reference portion of a CellRef and converts it from ALPHA-26 number format to 0-based base 10.static StringconvertNumToColString(int col) Takes in a 0-based base-10 column and returns a ALPHA-26 representation.static booleanisColumnWithnRange(String colStr, int lastColumnIndex) static booleanisPlainColumn(String refPart) static booleanisRowWithnRange(String rowStr, int lastRowIndex) static StringparseSheetName(String reference, int indexOfSheetNameDelimiter) static String[]separateAreaRefs(String reference) Separates Area refs in two parts and returns them as separate elements in a String array, each qualified with the sheet name (if present)static String[]separateRefParts(String reference)
-
Field Details
-
SHEET_NAME_DELIMITER
public static final char SHEET_NAME_DELIMITERThe character (!) that separates sheet names from cell references- See Also:
-
ABSOLUTE_REFERENCE_MARKER
public static final char ABSOLUTE_REFERENCE_MARKERThe character ($) that signifies a row or column value is absolute instead of relative- See Also:
-
-
Constructor Details
-
CellRefUtil
public CellRefUtil()
-
-
Method Details
-
convertNumToColString
Takes in a 0-based base-10 column and returns a ALPHA-26 representation. e.g. column #3 -> D- Parameters:
col- -- Returns:
- -
-
appendFormat
-
cellReferenceIsWithinRange
public static boolean cellReferenceIsWithinRange(String colStr, String rowStr, int lastColumnIndex, int lastRowIndex) Used to decide whether a name of the form "[A-Z]*[0-9]*" that appears in a formula can be interpreted as a cell reference. Names of that form can be also used for sheets and/or named ranges, and in those circumstances, the question of whether the potential cell reference is valid (in range) becomes important.Note - that the maximum sheet size varies across Excel versions:
POI currently targets BIFF8 (Excel 97-2003), so the following behaviour can be observed for this method:Notable cases Version File Format Last Column Last Row 97-2003 BIFF8 "IV" (2^8) 65536 (2^14) 2007 BIFF12 "XFD" (2^14) 1048576 (2^20) Notable cases Input Result "A", "1" true "a", "111" true "A", "65536" true "A", "65537" false "iv", "1" true "IW", "1" false "AAA", "1" false "a", "111" true "Sheet", "1" false - Parameters:
colStr- a string of only letter charactersrowStr- a string of only digit characterslastColumnIndex- -lastRowIndex- -- Returns:
trueif the row and col parameters are within range of a BIFF8 spreadsheet.
-
isColumnWithnRange
-
isRowWithnRange
-
convertColStringToIndex
takes in a column reference portion of a CellRef and converts it from ALPHA-26 number format to 0-based base 10.'A' -> 0 'Z' -> 25 'AA' -> 26 'IV' -> 255
- Parameters:
ref- -- Returns:
- zero based column index
-
separateRefParts
-
parseSheetName
-
separateAreaRefs
Separates Area refs in two parts and returns them as separate elements in a String array, each qualified with the sheet name (if present)- Parameters:
reference- -- Returns:
- array with one or two elements. never
null
-
isPlainColumn
-