public class CellReference extends java.lang.Object implements GenericRecord
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 |
---|---|
static class |
CellReference.NameType
Used to classify identifiers found in formulas as cell references or not.
(用于将公式中的标识符分类为单元格引用与否。)
|
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) |
Modifier and Type | Method and Description |
---|---|
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.
(用于决定公式中出现的“[AZ]*[0-9]*”形式的名称是否可以解释为单元格引用。)
|
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
(将标识符分类为简单 (2D) 单元格引用或命名范围名称)
|
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.
(接受 CellRef 的列引用部分并将其从 ALPHA-26 数字格式转换为基于 0 的基数 10。)
|
static java.lang.String |
convertNumToColString(int col)
Takes in a 0-based base-10 column and returns a ALPHA-26 representation.
(接受一个基于 0 的 base-10 列并返回一个 ALPHA-26 表示。)
|
boolean |
equals(java.lang.Object o)
Checks whether this cell reference is equal to another object.
(检查此单元格引用是否等于另一个对象。)
|
java.lang.String |
formatAsString()
Returns a text representation of this cell reference.
(返回此单元格引用的文本表示形式。)
|
java.lang.String |
formatAsString(boolean includeSheetName)
Returns a text representation of this cell reference and allows to control if the sheetname is included in the 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.
(返回单元格引用的三个部分、工作表名称(如果未提供,则返回 null)、基于 1 的行号和基于 A 的列字母。)
|
short |
getCol() |
java.util.Map<java.lang.String,java.util.function.Supplier<?>> |
getGenericProperties() |
int |
getRow() |
java.lang.String |
getSheetName() |
int |
hashCode() |
boolean |
isColAbsolute() |
static boolean |
isColumnWithinRange(java.lang.String colStr, SpreadsheetVersion ssVersion) |
static boolean |
isPartAbsolute(java.lang.String part) |
boolean |
isRowAbsolute() |
static boolean |
isRowWithinRange(int rowNum, SpreadsheetVersion ssVersion)
Determines whether
row is a valid row number for a given SpreadsheetVersion.
(确定 row 是否是给定 SpreadsheetVersion 的有效行号。)
|
static boolean |
isRowWithinRange(java.lang.String rowStr, SpreadsheetVersion ssVersion)
Determines whether
rowStr is a valid row number for a given SpreadsheetVersion.
(确定 rowStr 是否是给定 SpreadsheetVersion 的有效行号。)
|
java.lang.String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getGenericChildren, getGenericRecordType
public CellReference(java.lang.String cellRef)
public CellReference(int pRow, int pCol)
public CellReference(int pRow, short pCol)
public CellReference(Cell cell)
public CellReference(int pRow, int pCol, boolean pAbsRow, boolean pAbsCol)
public CellReference(java.lang.String pSheetName, int pRow, int pCol, boolean pAbsRow, boolean pAbsCol)
public int getRow()
public short getCol()
public boolean isRowAbsolute()
public boolean isColAbsolute()
public java.lang.String getSheetName()
null
if this is a 2D reference. Special characters are not escaped or delimited
(如果这是 2D 参考,则可能为 null。特殊字符不转义或分隔)
public static boolean isPartAbsolute(java.lang.String part)
public static int convertColStringToIndex(java.lang.String ref)
public static CellReference.NameType classifyCellReference(java.lang.String str, SpreadsheetVersion ssVersion)
public static boolean cellReferenceIsWithinRange(java.lang.String colStr, java.lang.String rowStr, SpreadsheetVersion ssVersion)
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)
(用于决定是否可以将出现在公式中的“[AZ]*[0-9]*”形式的名称解释为单元格引用。该形式的名称也可用于工作表和/或命名范围,在这些情况下,潜在单元格引用是否有效(在范围内)的问题变得很重要。注意 - 最大工作表大小因 Excel 版本而异: Version File Format Last Column Last Row 97-2003 BIFF8 "IV" (2^8) 65536 (2^14) 2007 BIFF12 "XFD" (2^14) 1048576 (2 ^20) POI 当前以 BIFF8 (Excel 97-2003) 为目标,因此可以观察到此方法的以下行为:输入结果“A”、“1”真“a”、“111”真“A”、“65536”真“A”、“65537”假“iv”、“1”真“IW”、“1”假“AAA”、“1”假“a”、“111”真“表”、“1”假)
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
colStr
- a string of only letter characters
(colStr - 一个只有字母字符的字符串)
rowStr
- a string of only digit characters
(rowStr - 只有数字字符的字符串)
true
if the row and col parameters are within range of a BIFF8 spreadsheet.
(如果 row 和 col 参数在 BIFF8 电子表格的范围内,则为 true。)
public static boolean isColumnWithinRange(java.lang.String colStr, SpreadsheetVersion ssVersion)
public static boolean isRowWithinRange(java.lang.String rowStr, SpreadsheetVersion ssVersion)
rowStr
is a valid row number for a given SpreadsheetVersion.
(确定 rowStr 是否是给定 SpreadsheetVersion 的有效行号。)
rowStr
- the numeric portion of an A1-style cell reference (1-based index)
(rowStr - A1 样式单元格引用的数字部分(基于 1 的索引))
ssVersion
- the spreadsheet version
(ssVersion - 电子表格版本)
java.lang.NumberFormatException
- if rowStr is not parseable as an integer
(java.lang.NumberFormatException - 如果 rowStr 不可解析为整数)
public static boolean isRowWithinRange(int rowNum, SpreadsheetVersion ssVersion)
row
is a valid row number for a given SpreadsheetVersion.
(确定 row 是否是给定 SpreadsheetVersion 的有效行号。)
rowNum
- the row number (0-based index)
(rowNum - 行号(从 0 开始的索引))
ssVersion
- the spreadsheet version
(ssVersion - 电子表格版本)
public static java.lang.String convertNumToColString(int col)
convertNumToColString(3)
returns
"D"
(接受一个基于 0 的 base-10 列并返回一个 ALPHA-26 表示。例如 convertNumToColString(3) 返回 "D")
public java.lang.String formatAsString()
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 |
public java.lang.String formatAsString(boolean includeSheetName)
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 |
includeSheetName
- If true and there is a sheet name set for this cell reference, the reference is prefixed with the sheet name and '!'
(includeSheetName - 如果为 true 并且为此单元格引用设置了工作表名称,则引用以工作表名称和“!”为前缀)
public java.lang.String toString()
toString
in class
java.lang.Object
public java.lang.String[] getCellRefParts()
formatAsString()
to properly turn references into strings.
(返回单元格引用的三个部分、工作表名称(如果未提供,则返回 null)、基于 1 的行号和基于 A 的列字母。这将不包括任何绝对引用的标记,因此请使用 formatAsString() 将引用正确地转换为字符串。)
public boolean equals(java.lang.Object o)
Two cells references are assumed to be equal if their string representations (formatAsString()
are equal.
equals
in class
java.lang.Object
public int hashCode()
hashCode
in class
java.lang.Object
public java.util.Map<java.lang.String,java.util.function.Supplier<?>> getGenericProperties()
getGenericProperties
in interface
GenericRecord
(接口 GenericRecord 中的 getGenericProperties)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.