public final class XSSFName extends java.lang.Object implements Name
Defined names are descriptive text that is used to represents a cell, range of cells, formula, or constant value. Use easy-to-understand names, such as Products, to refer to hard to understand ranges, such as Sales!C20:C30.
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sh = wb.createSheet("Sheet1");
//applies to the entire workbook
XSSFName name1 = wb.createName();
name1.setNameName("FMLA");
name1.setRefersToFormula("Sheet1!$B$3");
//applies to Sheet1
XSSFName name2 = wb.createName();
name2.setNameName("SheetLevelName");
name2.setComment("This name is scoped to Sheet1");
name2.setLocalSheetId(0);
name2.setRefersToFormula("Sheet1!$B$3");
(表示 SpreadsheetML 工作簿中定义的命名范围。定义的名称是用于表示单元格、单元格区域、公式或常数值的描述性文本。使用易于理解的名称(例如 Products)来指代难以理解的范围,例如 Sales!C20:C30。示例:XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sh = wb.createSheet("Sheet1"); //适用于整个工作簿 XSSFName name1 = wb.createName(); name1.setNameName("FMLA"); name1.setRefersToFormula("Sheet1!$B$3"); //适用于 Sheet1 XSSFName name2 = wb.createName(); name2.setNameName("SheetLevelName"); name2.setComment("此名称范围为 Sheet1"); name2.setLocalSheetId(0); name2.setRefersToFormula("Sheet1!$B$3");)
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BUILTIN_CONSOLIDATE_AREA
A built-in defined name that refers to a consolidation area
(一个内置的定义名称,指的是一个合并区域)
|
static java.lang.String |
BUILTIN_CRITERIA
A built-in defined name that refers to a range containing the criteria values to be used in applying an advanced filter to a range of data
(一个内置的定义名称,它指的是一个范围,该范围包含将高级过滤器应用于数据范围的条件值)
|
static java.lang.String |
BUILTIN_DATABASE
A built-in defined name that specified that the range specified is from a database data source
(指定范围来自数据库数据源的内置定义名称)
|
static java.lang.String |
BUILTIN_EXTRACT
this defined name refers to the range containing the filtered output values resulting from applying an advanced filter criteria to a source range
(此定义的名称是指包含通过将高级过滤条件应用于源范围而产生的过滤输出值的范围)
|
static java.lang.String |
BUILTIN_FILTER_DB
?an be one of the following this defined name refers to a range to which an advanced filter has been applied.
(? 可以是以下之一,此定义的名称是指已应用高级过滤器的范围。)
|
static java.lang.String |
BUILTIN_PRINT_AREA
A built-in defined name that specifies the workbook's print area
(指定工作簿打印区域的内置定义名称)
|
static java.lang.String |
BUILTIN_PRINT_TITLE
A built-in defined name that specifies the row(s) or column(s) to repeat at the top of each printed page.
(一个内置的定义名称,指定要在每个打印页面的顶部重复的行或列。)
|
static java.lang.String |
BUILTIN_SHEET_TITLE
A built-in defined name that refers to a sheet title.
(指代工作表标题的内置定义名称。)
|
| Modifier | Constructor and Description |
|---|---|
protected |
XSSFName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName name, XSSFWorkbook workbook)
Creates an XSSFName object - called internally by XSSFWorkbook.
(创建一个 XSSFName 对象 - 由 XSSFWorkbook 内部调用。)
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object o)
Compares this name to the specified object.
(将此名称与指定的对象进行比较。)
|
java.lang.String |
getComment()
Returns the comment the user provided when the name was created.
(返回创建名称时用户提供的评论。)
|
protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName |
getCTName()
Returns the underlying named range object
(返回底层命名范围对象)
|
boolean |
getFunction()
Indicates that the defined name refers to a user-defined function.
(表示定义的名称是指用户定义的函数。)
|
int |
getFunctionGroupId()
Returns the function group index if the defined name refers to a function.
(如果定义的名称引用函数,则返回函数组索引。)
|
java.lang.String |
getNameName()
Returns the name that will appear in the user interface for the defined name.
(返回将出现在用户界面中的已定义名称的名称。)
|
java.lang.String |
getRefersToFormula()
Returns the formula that the name is defined to refer to.
(返回定义名称以引用的公式。)
|
int |
getSheetIndex()
Returns the sheet index this name applies to.
(返回此名称适用的工作表索引。)
|
java.lang.String |
getSheetName()
Get the sheets name which this named range is referenced to
(获取此命名范围所引用的工作表名称)
|
int |
hashCode() |
boolean |
isDeleted()
Checks if this name points to a cell that no longer exists
(检查此名称是否指向不再存在的单元格)
|
boolean |
isFunctionName()
Is the name refers to a user-defined function ?
(名称是指用户定义的函数吗?)
|
boolean |
isHidden()
Checks if this name is hidden, eg one of the built-in Excel internal names
(检查此名称是否隐藏,例如内置 Excel 内部名称之一)
|
void |
setComment(java.lang.String comment)
Specifies the comment the user provided when the name was created.
(指定创建名称时用户提供的注释。)
|
void |
setFunction(boolean value)
Indicates that the defined name refers to a user-defined function.
(表示定义的名称是指用户定义的函数。)
|
void |
setFunctionGroupId(int functionGroupId)
Specifies the function group index if the defined name refers to a function.
(如果定义的名称引用函数,则指定函数组索引。)
|
void |
setNameName(java.lang.String name)
Sets the name that will appear in the user interface for the defined name.
(为定义的名称设置将出现在用户界面中的名称。)
|
void |
setRefersToFormula(java.lang.String formulaText)
Sets the formula that the name is defined to refer to.
(设置定义名称以引用的公式。)
|
void |
setSheetIndex(int index)
Tell Excel that this name applies to the worksheet with the specified index instead of the entire workbook.
(告诉 Excel 此名称适用于具有指定索引的工作表,而不是整个工作簿。)
|
public static final java.lang.String BUILTIN_PRINT_AREA
public static final java.lang.String BUILTIN_PRINT_TITLE
public static final java.lang.String BUILTIN_CRITERIA
public static final java.lang.String BUILTIN_EXTRACT
public static final java.lang.String BUILTIN_FILTER_DB
public static final java.lang.String BUILTIN_CONSOLIDATE_AREA
public static final java.lang.String BUILTIN_DATABASE
public static final java.lang.String BUILTIN_SHEET_TITLE
protected XSSFName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName name,
XSSFWorkbook workbook)
name - - the xml bean that holds data represenring this defined name.
workbook - - the workbook object associated with the name
XSSFWorkbook.createName()
protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName getCTName()
public java.lang.String getNameName()
getNameName in interface
Name
public void setNameName(java.lang.String name)
A name must always be unique within its scope. POI prevents you from defining a name that is not unique within its scope. However you can use the same name in different scopes. Example:
//by default names are workbook-global
XSSFName name;
name = workbook.createName();
name.setNameName("sales_08");
name = workbook.createName();
name.setNameName("sales_08"); //will throw an exception: "The workbook already contains this name (case-insensitive)"
//create sheet-level name
name = workbook.createName();
name.setSheetIndex(0); //the scope of the name is the first sheet
name.setNameName("sales_08"); //ok
name = workbook.createName();
name.setSheetIndex(0);
name.setNameName("sales_08"); //will throw an exception: "The sheet already contains this name (case-insensitive)"
setNameName in interface
Name
name - name of this defined name
java.lang.IllegalArgumentException - if the name is invalid or the workbook already contains this name (case-insensitive)
public java.lang.String getRefersToFormula()
Name
getRefersToFormula in interface
Name
null if it has not been set yet. Never empty string
Name.setRefersToFormula(String)
public void setRefersToFormula(java.lang.String formulaText)
Name
'My Sheet'!$A$38.3HR!$A$1:$Z$345SUM(Sheet1!A1,Sheet2!B2) -PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)
Note: Using relative values like 'A1:B1' can lead to unexpected moving of the cell that the name points to when working with the workbook in Microsoft Excel, usually using absolute references like '$A$1:$B$1' avoids this, see also https://superuser.com/a/1031047/126954
-
Specified by:
-
setRefersToFormula in interface
Name
-
Parameters:
-
formulaText - the reference for this name
-
isDeleted
public boolean isDeleted()
Description copied from interface: Name
Checks if this name points to a cell that no longer exists
-
setSheetIndex
public void setSheetIndex(int index)
Tell Excel that this name applies to the worksheet with the specified index instead of the entire workbook.
-
Specified by:
-
setSheetIndex in interface
Name
-
Parameters:
-
index - the sheet index this name applies to, -1 unsets this property making the name workbook-global
-
getSheetIndex
public int getSheetIndex()
Returns the sheet index this name applies to.
-
Specified by:
-
getSheetIndex in interface
Name
-
Returns:
-
the sheet index this name applies to, -1 if this name applies to the entire workbook
-
setFunction
public void setFunction(boolean value)
Indicates that the defined name refers to a user-defined function. This attribute is used when there is an add-in or other code project associated with the file.
-
Specified by:
-
setFunction in interface
Name
-
Parameters:
-
value -
true indicates the name refers to a function.
-
getFunction
public boolean getFunction()
Indicates that the defined name refers to a user-defined function. This attribute is used when there is an add-in or other code project associated with the file.
-
Returns:
-
true indicates the name refers to a function.
-
setFunctionGroupId
public void setFunctionGroupId(int functionGroupId)
Specifies the function group index if the defined name refers to a function. The function group defines the general category for the function. This attribute is used when there is an add-in or other code project associated with the file.
-
Parameters:
-
functionGroupId - the function group index that defines the general category for the function
-
getFunctionGroupId
public int getFunctionGroupId()
Returns the function group index if the defined name refers to a function. The function group defines the general category for the function. This attribute is used when there is an add-in or other code project associated with the file.
-
Returns:
-
the function group index that defines the general category for the function
-
getSheetName
public java.lang.String getSheetName()
Get the sheets name which this named range is referenced to
-
Specified by:
-
getSheetName in interface
Name
-
Returns:
-
sheet name, which this named range referred to. Empty string if the referenced sheet name was not found.
-
isFunctionName
public boolean isFunctionName()
Is the name refers to a user-defined function ?
-
Specified by:
-
isFunctionName in interface
Name
-
Returns:
-
true if this name refers to a user-defined function
-
isHidden
public boolean isHidden()
Checks if this name is hidden, eg one of the built-in Excel internal names
-
getComment
public java.lang.String getComment()
Returns the comment the user provided when the name was created.
-
Specified by:
-
getComment in interface
Name
-
Returns:
-
the user comment for this named range
-
setComment
public void setComment(java.lang.String comment)
Specifies the comment the user provided when the name was created.
-
Specified by:
-
setComment in interface
Name
-
Parameters:
-
comment - the user comment for this named range
-
hashCode
public int hashCode()
-
Overrides:
-
hashCode in class
java.lang.Object
-
equals
public boolean equals(java.lang.Object o)
Compares this name to the specified object. The result is
true if the argument is XSSFName and the underlying CTDefinedName bean equals to the CTDefinedName representing this name
-
Overrides:
-
equals in class
java.lang.Object
-
Parameters:
-
o - the object to compare this
XSSFName against.
-
Returns:
-
true if the
XSSFName are equal;
false otherwise.
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.