org.apache.poi.ss.util
Class CellReference
- java.lang.Object
-
- org.apache.poi.ss.util.CellReference
-
- Direct Known Subclasses:
- CellReference
public class CellReference extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classCellReference.NameTypeUsed to classify identifiers found in formulas as cell references or not.
-
Constructor Summary
Constructors Constructor and Description CellReference(Cell cell)CellReference(int pRow, int pCol)CellReference(int pRow, int pCol, boolean pAbsRow, boolean pAbsCol)CellReference(int pRow, short pCol)CellReference(java.lang.String cellRef)Create an cell ref from a string representation.CellReference(java.lang.String pSheetName, int pRow, int pCol, boolean pAbsRow, boolean pAbsCol)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static booleancellReferenceIsWithinRange(java.lang.String colStr, java.lang.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.static CellReference.NameTypeclassifyCellReference(java.lang.String str, SpreadsheetVersion ssVersion)Classifies an identifier as either a simple (2D) cell reference or a named range namestatic intconvertColStringToIndex(java.lang.String ref)takes in a column reference portion of a CellRef and converts it from ALPHA-26 number format to 0-based base 10.static java.lang.StringconvertNumToColString(int col)Takes in a 0-based base-10 column and returns a ALPHA-26 representation.booleanequals(java.lang.Object o)Checks whether this cell reference is equal to another object.java.lang.StringformatAsString()Returns a text representation of this cell reference.java.lang.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.shortgetCol()intgetRow()java.lang.StringgetSheetName()inthashCode()booleanisColAbsolute()static booleanisColumnWithnRange(java.lang.String colStr, SpreadsheetVersion ssVersion)static booleanisPartAbsolute(java.lang.String part)booleanisRowAbsolute()static booleanisRowWithnRange(java.lang.String rowStr, SpreadsheetVersion ssVersion)java.lang.StringtoString()
-
-
-
Constructor Detail
-
CellReference
public CellReference(java.lang.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
public CellReference(int pRow, int pCol)
-
CellReference
public CellReference(int pRow, short pCol)
-
CellReference
public CellReference(Cell cell)
-
CellReference
public CellReference(int pRow, int pCol, boolean pAbsRow, boolean pAbsCol)
-
CellReference
public CellReference(java.lang.String pSheetName, int pRow, int pCol, boolean pAbsRow, boolean pAbsCol)
-
-
Method Detail
-
getRow
public int getRow()
-
getCol
public short getCol()
-
isRowAbsolute
public boolean isRowAbsolute()
-
isColAbsolute
public boolean isColAbsolute()
-
getSheetName
public java.lang.String getSheetName()
- Returns:
- possibly
nullif this is a 2D reference. Special characters are not escaped or delimited
-
isPartAbsolute
public static boolean isPartAbsolute(java.lang.String part)
-
convertColStringToIndex
public static int convertColStringToIndex(java.lang.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- Returns:
- zero based column index
-
classifyCellReference
public static CellReference.NameType classifyCellReference(java.lang.String str, SpreadsheetVersion ssVersion)
Classifies an identifier as either a simple (2D) cell reference or a named range name- Returns:
- one of the values from NameType
-
cellReferenceIsWithinRange
public static boolean cellReferenceIsWithinRange(java.lang.String colStr, java.lang.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:
POI currently targets BIFF8 (Excel 97-2003), so the following behaviour can be observed for this method:Version File Format Last Column Last Row 97-2003 BIFF8 "IV" (2^8) 65536 (2^14) 2007 BIFF12 "XFD" (2^14) 1048576 (2^20) 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 characters- Returns:
trueif the row and col parameters are within range of a BIFF8 spreadsheet.
-
isColumnWithnRange
public static boolean isColumnWithnRange(java.lang.String colStr, SpreadsheetVersion ssVersion)
-
isRowWithnRange
public static boolean isRowWithnRange(java.lang.String rowStr, SpreadsheetVersion ssVersion)
-
convertNumToColString
public static java.lang.String convertNumToColString(int col)
Takes in a 0-based base-10 column and returns a ALPHA-26 representation. eg column #3 -> D
-
formatAsString
public java.lang.String formatAsString()
Returns a text representation of this cell reference. Example return values:Result Comment A1 Cell reference without sheet Sheet1!A1 Standard sheet name 'O''Brien''s Sales'!A1' Sheet name with special characters - Returns:
- the text representation of this cell reference as it would appear in a formula.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getCellRefParts
public java.lang.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 useformatAsString()to properly turn references into strings.
-
equals
public boolean equals(java.lang.Object o)
Checks whether this cell reference is equal to another object.Two cells references are assumed to be equal if their string representations (
formatAsString()are equal.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG