Common conversion functions between Excel style A1, C27 style cell references, and POI usermodel style row=0, column=0 style references. Handles sheet-based and sheet-free references as well, eg "Sheet1!A1" and "$B$72"
Use CellReference when the concept of
relative/absolute does apply (such as a cell reference in a formula).
Use CellAddress when you want to refer to the location of a cell in a sheet
when the concept of relative/absolute does not apply (such as the anchor location
of a cell comment).
CellReferences have a concept of "sheet", while CellAddresses do not.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static enum | CellReference.
Used to classify identifiers found in formulas as cell references or not. |
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private final boolean | |
| private final boolean | |
| private final int | |
| private final String | |
| private static final char | ABSOLUTE_REFERENCE_MARKER
The character ($) that signifies a row or column value is absolute instead of relative |
| private static final Pattern | CELL_REF_PATTERN
Matches a run of one or more letters followed by a run of one or more digits. |
| private static final Pattern | COLUMN_REF_PATTERN
Matches a run of one or more letters. |
| private static final Pattern | NAMED_RANGE_NAME_PATTERN
Named range names must start with a letter or underscore. |
| private static final Pattern | ROW_REF_PATTERN
Matches a run of one or more letters. |
| private static final char | SHEET_NAME_DELIMITER
The character (!) that separates sheet names from cell references |
| private static final char | SPECIAL_NAME_DELIMITER
The character (') used to quote sheet names when they contain special characters |
| private static final Pattern | STRICTLY_CELL_REF_PATTERN
Matches references only where row and column are included. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | appendCellReference(StringBuilder sb)
Appends cell reference with '$' markers for absolute values as required. |
| pack-priv void | appendR1C1CellReference(StringBuilder sb)
Appends R1C1 cell reference with '$' markers for absolute values as required. |
| public static boolean | Returns: true if the row and col parameters are within range of a BIFF8 spreadsheet.a string of only letter characters colStr, String a string of only digit characters rowStr, SpreadsheetVersion ssVersion)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. |
| public static CellReference. | Returns: one of the values fromNameTypeClassifies an identifier as either a simple (2D) cell reference or a named range name |
| public static int | Returns: zero based column indextakes in a column reference portion of a CellRef and converts it from ALPHA-26 number format to 0-based base 10. |
| public static String | convertNumToColString(int col)
Takes in a 0-based base-10 column and returns a ALPHA-26 representation. |
| public boolean | equals(Object
the reference object with which to compare. o)Overrides java. Checks whether this cell reference is equal to another object. |
| public String | Returns: the text representation of this cell reference as it would appear in a formula.Returns a text representation of this cell reference in R1C1 format. |
| public String | Returns: the text representation of this cell reference as it would appear in a formula.If true and there is a sheet name set for this cell reference,
the reference is prefixed with the sheet name and '!' includeSheetName)Returns a text representation of this cell reference in R1C1 format and allows to control if the sheetname is included in the reference. |
| public String | Returns: the text representation of this cell reference as it would appear in a formula.Returns a text representation of this cell reference. |
| public String | Returns: the text representation of this cell reference as it would appear in a formula.If true and there is a sheet name set for this cell reference,
the reference is prefixed with the sheet name and '!' includeSheetName)Returns a text representation of this cell reference and allows to control if the sheetname is included in the reference. |
| public String[] | Returns: String array of { sheetName, rowString, colString }Returns the three parts of the cell reference, the Sheet name (or null if none supplied), the 1 based row number, and the A based column letter. |
| public short | |
| public Map | |
| public int | |
| public String | Returns: possiblynull if this is a 2D reference. Special characters are not
escaped or delimited
|
| public int | |
| public boolean | |
| public static boolean | |
| public static boolean | |
| public boolean | |
| public static boolean | isRowWithinRange(String
the numeric portion of an A1-style cell reference (1-based index) rowStr, SpreadsheetVersion the spreadsheet version ssVersion)Determines whether |
| public static boolean | isRowWithinRange(int
the row number (0-based index) rowNum, SpreadsheetVersion the spreadsheet version ssVersion)Determines whether |
| private static String | |
| private static CellReference. | Returns: 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.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. reference)Separates the sheet name, row, and columns from a cell reference string. |
| public String | |
| private static CellReference. |
| _colIndex | back to summary |
|---|---|
| private final int _colIndex | |
| _isColAbs | back to summary |
|---|---|
| private final boolean _isColAbs | |
| _isRowAbs | back to summary |
|---|---|
| private final boolean _isRowAbs | |
| _rowIndex | back to summary |
|---|---|
| private final int _rowIndex | |
| _sheetName | back to summary |
|---|---|
| private final String _sheetName | |
| ABSOLUTE_REFERENCE_MARKER | back to summary |
|---|---|
| private static final char ABSOLUTE_REFERENCE_MARKER The character ($) that signifies a row or column value is absolute instead of relative | |
| CELL_REF_PATTERN | back to summary |
|---|---|
| private static final Pattern CELL_REF_PATTERN Matches a run of one or more letters followed by a run of one or more digits. Both the letter and number groups are optional. The run of letters is group 1 and the run of digits is group 2. Each group may optionally be prefixed with a single '$'. | |
| COLUMN_REF_PATTERN | back to summary |
|---|---|
| private static final Pattern COLUMN_REF_PATTERN Matches a run of one or more letters. The run of letters is group 1. References may optionally include a single '$' before the group, but these are excluded from the Matcher.group(int). | |
| NAMED_RANGE_NAME_PATTERN | back to summary |
|---|---|
| private static final Pattern NAMED_RANGE_NAME_PATTERN Named range names must start with a letter or underscore. Subsequent characters may include digits or dot. (They can even end in dot). | |
| ROW_REF_PATTERN | back to summary |
|---|---|
| private static final Pattern ROW_REF_PATTERN Matches a run of one or more letters. The run of numbers is group 1. References may optionally include a single '$' before the group, but these are excluded from the Matcher.group(int). | |
| SHEET_NAME_DELIMITER | back to summary |
|---|---|
| private static final char SHEET_NAME_DELIMITER The character (!) that separates sheet names from cell references | |
| SPECIAL_NAME_DELIMITER | back to summary |
|---|---|
| private static final char SPECIAL_NAME_DELIMITER The character (') used to quote sheet names when they contain special characters | |
| STRICTLY_CELL_REF_PATTERN | back to summary |
|---|---|
| private static final Pattern STRICTLY_CELL_REF_PATTERN Matches references only where row and column are included. Matches a run of one or more letters followed by a run of one or more digits. If a reference does not match this pattern, it might match COLUMN_REF_PATTERN or ROW_REF_PATTERN References may optionally include a single '$' before each group, but these are excluded from the Matcher.group(int). | |
| CellReference | back to summary |
|---|---|
| public CellReference(String cellRef) Create an cell ref from a string representation. Sheet names containing special characters should be delimited and escaped as per normal syntax rules for formulas.
| |
| CellReference | back to summary |
|---|---|
| public CellReference(int pRow, int pCol) | |
| CellReference | back to summary |
|---|---|
| public CellReference(int pRow, short pCol) | |
| CellReference | back to summary |
|---|---|
| public CellReference(Cell cell) | |
| CellReference | back to summary |
|---|---|
| public CellReference(int pRow, int pCol, boolean pAbsRow, boolean pAbsCol) | |
| CellReference | back to summary |
|---|---|
| public CellReference(String pSheetName, int pRow, int pCol, boolean pAbsRow, boolean pAbsCol) | |
| appendCellReference | back to summary |
|---|---|
| pack-priv void appendCellReference(StringBuilder sb) Appends cell reference with '$' markers for absolute values as required. Sheet name is not included. | |
| appendR1C1CellReference | back to summary |
|---|---|
| pack-priv void appendR1C1CellReference(StringBuilder sb) Appends R1C1 cell reference with '$' markers for absolute values as required. Sheet name is not included. | |
| cellReferenceIsWithinRange | back to summary | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public static boolean cellReferenceIsWithinRange(String colStr, String rowStr, SpreadsheetVersion ssVersion) 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:
| |||||||||||||||||||||||||||||||||
| classifyCellReference | back to summary |
|---|---|
| public static CellReference. Classifies an identifier as either a simple (2D) cell reference or a named range name
| |
| convertColStringToIndex | back to summary |
|---|---|
| public static int convertColStringToIndex(String ref) 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
| |
| convertNumToColString | back to summary |
|---|---|
| public static String convertNumToColString(int col) Takes in a 0-based base-10 column and returns a ALPHA-26
representation.
eg | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Checks whether this cell reference is equal to another object.
Two cells references are assumed to be equal if their string representations
(
| |
| formatAsR1C1String | back to summary | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| public String formatAsR1C1String() Returns a text representation of this cell reference in R1C1 format. Example return values:
| |||||||||
| formatAsR1C1String | back to summary | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| public String formatAsR1C1String(boolean includeSheetName) Returns a text representation of this cell reference in R1C1 format and allows to control if the sheetname is included in the reference. Example return values:
| |||||||||
| formatAsString | back to summary | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| public String formatAsString() Returns a text representation of this cell reference. Example return values:
| |||||||||
| formatAsString | back to summary | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| public String formatAsString(boolean includeSheetName) Returns a text representation of this cell reference and allows to control if the sheetname is included in the reference. Example return values:
| |||||||||
| getCellRefParts | back to summary |
|---|---|
| public String[] getCellRefParts() Returns the three parts of the cell reference, the
Sheet name (or null if none supplied), the 1 based
row number, and the A based column letter.
This will not include any markers for absolute
references, so use
| |
| getCol | back to summary |
|---|---|
| public short getCol() | |
| getGenericProperties | back to summary |
|---|---|
| public Map Implements org.
| |
| getRow | back to summary |
|---|---|
| public int getRow() | |
| getSheetName | back to summary |
|---|---|
public String getSheetName()
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isColAbsolute | back to summary |
|---|---|
| public boolean isColAbsolute() | |
| isColumnWithinRange | back to summary |
|---|---|
| public static boolean isColumnWithinRange(String colStr, SpreadsheetVersion ssVersion) | |
| isPartAbsolute | back to summary |
|---|---|
| public static boolean isPartAbsolute(String part) | |
| isRowAbsolute | back to summary |
|---|---|
| public boolean isRowAbsolute() | |
| isRowWithinRange | back to summary |
|---|---|
| public static boolean isRowWithinRange(String rowStr, SpreadsheetVersion ssVersion) Determines whether
| |
| isRowWithinRange | back to summary |
|---|---|
| public static boolean isRowWithinRange(int rowNum, SpreadsheetVersion ssVersion) Determines whether
| |
| parseSheetName | back to summary |
|---|---|
| private static String parseSheetName(String reference, int indexOfSheetNameDelimiter) | |
| separateRefParts | back to summary |
|---|---|
| private static CellReference. Separates the sheet name, row, and columns from a cell reference string.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| validateNamedRangeName | back to summary |
|---|---|
| private static CellReference. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final String | |
| pack-priv final String | |
| pack-priv final String |
| Access | Constructor and Description |
|---|---|
| private |
| colRef | back to summary |
|---|---|
| pack-priv final String colRef | |
| rowRef | back to summary |
|---|---|
| pack-priv final String rowRef | |
| sheetName | back to summary |
|---|---|
| pack-priv final String sheetName | |
| CellRefParts | back to summary |
|---|---|
| private CellRefParts(String sheetName, String rowRef, String colRef) | |
| Modifier and Type | Field and Description |
|---|---|
| public static final CellReference. | |
| public static final CellReference. | |
| public static final CellReference. | |
| public static final CellReference. | |
| public static final CellReference. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static CellReference. | |
| public static CellReference. |
| BAD_CELL_OR_NAMED_RANGE | back to summary |
|---|---|
| public static final CellReference. | |
| CELL | back to summary |
|---|---|
| public static final CellReference. | |
| COLUMN | back to summary |
|---|---|
| public static final CellReference. | |
| NAMED_RANGE | back to summary |
|---|---|
| public static final CellReference. | |
| ROW | back to summary |
|---|---|
| public static final CellReference. | |
| NameType | back to summary |
|---|---|
| private NameType() | |
| valueOf | back to summary |
|---|---|
| public static CellReference. | |
| values | back to summary |
|---|---|
| public static CellReference. | |