Modifier and Type | Method and Description |
---|---|
java.lang.String |
getComment()
Returns the comment the user provided when the name was created.
(返回创建名称时用户提供的评论。)
|
java.lang.String |
getNameName()
Gets the name of the named range
(获取命名范围的名称)
|
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
(获取此命名范围所引用的工作表名称)
|
boolean |
isDeleted()
Checks if this name points to a cell that no longer exists
(检查此名称是否指向不再存在的单元格)
|
boolean |
isFunctionName()
Checks if this name is a function name
(检查此名称是否为函数名称)
|
boolean |
isHidden()
Checks if this name is hidden, eg one of the built-in Excel internal names
(检查此名称是否隐藏,例如内置 Excel 内部名称之一)
|
void |
setComment(java.lang.String comment)
Sets 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 |
setNameName(java.lang.String nameName)
Sets the name of the named range
(设置命名范围的名称)
|
void |
setRefersToFormula(java.lang.String formulaText)
Sets the formula that the name is defined to refer to.
(设置定义名称以引用的公式。)
|
void |
setSheetIndex(int index)
Specifies if the defined name is a local name, and if so, which sheet it is on.
(指定定义的名称是否是本地名称,如果是,那么它在哪个工作表上。)
|
java.lang.String |
toString() |
public java.lang.String getSheetName()
getSheetName
in interface
Name
(接口名称中的 getSheetName)
public java.lang.String getNameName()
Name
getNameName
in interface
Name
(接口名称中的getNameName)
public void setNameName(java.lang.String nameName)
The following is a list of syntax rules that you need to be aware of when you create and edit names.
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:
(设置命名范围的名称 以下是创建和编辑名称时需要注意的语法规则列表。有效字符 名称的第一个字符必须是字母、下划线字符 (_) 或反斜杠 ()。名称中的剩余字符可以是字母、数字、句点和下划线字符。不允许单元格引用 名称不能与单元格引用相同,例如 Z$100 或 R1C1。空格无效 空格不允许作为名称的一部分。使用下划线字符 (_) 和句点 (.) 作为单词分隔符,例如 Sales_Tax 或 First.Quarter。名称长度 名称最多可包含 255 个字符。区分大小写 名称可以包含大写和小写字母。名称在其范围内必须始终是唯一的。 POI 阻止您定义在其范围内不唯一的名称。但是,您可以在不同的范围内使用相同的名称。示例://默认名称是工作簿全局 HSSFName 名称;名称 = 工作簿.createName(); name.setNameName("sales_08");名称 = 工作簿.createName(); name.setNameName("sales_08"); //将抛出异常:“工作簿已包含此名称(不区分大小写)” //创建工作表级名称 name = workbook.createName(); name.setSheetIndex(0); //名称的范围是第一张表 name.setNameName("sales_08"); //ok name = workbook.createName(); name.setSheetIndex(0); name.setNameName("sales_08"); //将抛出异常:“工作表已包含此名称(不区分大小写)”)//by default names are workbook-global HSSFName 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
(接口名称中的 setNameName)
nameName
- named range name to set
(nameName - 要设置的命名范围名称)
java.lang.IllegalArgumentException
- if the name is invalid or the name already exists (case-insensitive)
(java.lang.IllegalArgumentException - 如果名称无效或名称已存在(不区分大小写))
public void setRefersToFormula(java.lang.String formulaText)
Name
'My Sheet'!$A$3
8.3
HR!$A$1:$Z$345
SUM(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
(设置定义名称以引用的公式。以下是代表性示例: 'My Sheet'!$A$3 8.3 HR!$A$1:$Z$345 SUM(Sheet1!A1,Sheet2!B2) -PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount) 注意:使用相对值像 'A1:B1' 可能会导致在 Microsoft Excel 中使用工作簿时名称指向的单元格发生意外移动,通常使用像 '$A$1:$B$1' 这样的绝对引用可以避免这种情况,另请参见 https:/ /superuser.com/a/1031047/126954)
-
Specified by:
-
setRefersToFormula
in interface
Name
-
Parameters:
-
formulaText
- the reference for this name
-
getRefersToFormula
public java.lang.String getRefersToFormula()
Description copied from interface: Name
Returns the formula that the name is defined to refer to.
-
Specified by:
-
getRefersToFormula
in interface
Name
-
Returns:
-
the reference for this name,
null
if it has not been set yet. Never empty string
-
See Also:
-
Name.setRefersToFormula(String)
-
isDeleted
public boolean isDeleted()
Description copied from interface: Name
Checks if this name points to a cell that no longer exists
-
isFunctionName
public boolean isFunctionName()
Checks if this name is a function name
-
Specified by:
-
isFunctionName
in interface
Name
-
Returns:
-
true if this name is a function name
-
isHidden
public boolean isHidden()
Checks if this name is hidden, eg one of the built-in Excel internal names
-
toString
public java.lang.String toString()
-
Overrides:
-
toString
in class
java.lang.Object
-
setSheetIndex
public void setSheetIndex(int index)
Specifies if the defined name is a local name, and if so, which sheet it is on.
-
Specified by:
-
setSheetIndex
in interface
Name
-
Parameters:
-
index
- if greater than 0, the defined name is a local name and the value MUST be a 0-based index to the collection of sheets as they appear in the workbook.
-
Throws:
-
java.lang.IllegalArgumentException
- if the sheet index is invalid.
-
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
-
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)
Sets 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
-
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.
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.