Top Description Fields Constructors Methods
org.apache.poi.hssf.usermodel

public final Class HSSFName

extends Object
implements Name
Class Inheritance
All Implemented Interfaces
org.apache.poi.ss.usermodel.Name
Imports
org.apache.poi.hssf.model.HSSFFormulaParser, .InternalWorkbook, org.apache.poi.hssf.record.NameCommentRecord, .NameRecord, org.apache.poi.ss.SpreadsheetVersion, org.apache.poi.ss.formula.FormulaType, org.apache.poi.ss.formula.ptg.Ptg, org.apache.poi.ss.usermodel.Name, org.apache.poi.ss.util.CellReference

High Level Representation of a 'defined name' which could be a 'built-in' name, 'named range' or name of a user defined function.

Field Summary

Modifier and TypeField and Description
private final HSSFWorkbook
private final NameCommentRecord
private final NameRecord

Constructor Summary

AccessConstructor and Description
pack-priv
HSSFName(HSSFWorkbook
workbook object associated with the sheet.
book
,
NameRecord
the Name Record
name
)

Creates new HSSFName - called by HSSFWorkbook to create a name from scratch.

pack-priv
HSSFName(final HSSFWorkbook
workbook object associated with the sheet.
book
,
final NameRecord
the Name Record
name
,
final NameCommentRecord
the Name Comment Record, optional.
comment
)

Creates new HSSFName - called by HSSFWorkbook to create a name from scratch.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the user comment for this named range
getComment
()

Implements org.apache.poi.ss.usermodel.Name.getComment.

Returns the comment the user provided when the name was created.

public String

Returns:

text name of this defined name
getNameName
()

Implements org.apache.poi.ss.usermodel.Name.getNameName.

Gets the name of the named range

public String
getRefersToFormula()

Implements org.apache.poi.ss.usermodel.Name.getRefersToFormula.

Returns the formula that the name is defined to refer to.

public int

Returns:

the sheet index this name applies to, -1 if this name applies to the entire workbook
getSheetIndex
()

Implements org.apache.poi.ss.usermodel.Name.getSheetIndex.

Returns the sheet index this name applies to.

public String

Returns:

sheet name, which this named range referred to
getSheetName
()

Implements org.apache.poi.ss.usermodel.Name.getSheetName.

Get the sheets name which this named range is referenced to

public boolean
isDeleted()

Implements org.apache.poi.ss.usermodel.Name.isDeleted.

Checks if this name points to a cell that no longer exists

public boolean

Returns:

true if this name is a function name
isFunctionName
()

Implements org.apache.poi.ss.usermodel.Name.isFunctionName.

Checks if this name is a function name

public boolean

Returns:

true if this name is a hidden one
isHidden
()

Implements org.apache.poi.ss.usermodel.Name.isHidden.

Checks if this name is hidden, eg one of the built-in Excel internal names

public void
setComment(String
the user comment for this named range
comment
)

Implements org.apache.poi.ss.usermodel.Name.setComment.

Sets the comment the user provided when the name was created.

public void
setFunction(boolean
true indicates the name refers to a function.
value
)

Implements org.apache.poi.ss.usermodel.Name.setFunction.

Indicates that the defined name refers to a user-defined function.

pack-priv void
setNameDefinition(Ptg[]
the sequence of Ptgs for the formula.
ptgs
)

Sets the NameParsedFormula structure that specifies the formula for the defined name.

public void
setNameName(String
named range name to set
nameName
)

Implements org.apache.poi.ss.usermodel.Name.setNameName.

Sets the name of the named range

The following is a list of syntax rules that you need to be aware of when you create and edit names.

public void
setRefersToFormula(String
the reference for this name
formulaText
)

Implements org.apache.poi.ss.usermodel.Name.setRefersToFormula.

Sets the formula that the name is defined to refer to.

public void
setSheetIndex(int
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.
index
)

Implements org.apache.poi.ss.usermodel.Name.setSheetIndex.

Specifies if the defined name is a local name, and if so, which sheet it is on.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private static void
validateName(String name)

https://support.office.com/en-us/article/Define-and-use-names-in-formulas-4D0F13AC-53B7-422E-AFD2-ABD7FF379C64#bmsyntax_rules_for_names Valid characters: First character: { letter | underscore | backslash } Remaining characters: { letter | number | period | underscore } Cell shorthand: cannot be { "C" | "c" | "R" | "r" } Cell references disallowed: cannot be a cell reference $A$1 or R1C1 Spaces are not valid (follows from valid characters above) Name length: (XSSF-specific?) 255 characters maximum Case sensitivity: all names are case-insensitive Uniqueness: must be unique (for names with the same scope)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_bookback to summary
private final HSSFWorkbook _book
_commentRecback to summary
private final NameCommentRecord _commentRec
_definedNameRecback to summary
private final NameRecord _definedNameRec

Constructor Detail

HSSFNameback to summary
pack-priv HSSFName(HSSFWorkbook book, NameRecord name)

Creates new HSSFName - called by HSSFWorkbook to create a name from scratch.

Parameters
book:HSSFWorkbook

workbook object associated with the sheet.

name:NameRecord

the Name Record

See Also
org.apache.poi.hssf.usermodel.HSSFWorkbook#createName()
HSSFNameback to summary
pack-priv HSSFName(final HSSFWorkbook book, final NameRecord name, final NameCommentRecord comment)

Creates new HSSFName - called by HSSFWorkbook to create a name from scratch.

Parameters
book:HSSFWorkbook

workbook object associated with the sheet.

name:NameRecord

the Name Record

comment:NameCommentRecord

the Name Comment Record, optional.

See Also
org.apache.poi.hssf.usermodel.HSSFWorkbook#createName()

Method Detail

getCommentback to summary
public String getComment()

Implements org.apache.poi.ss.usermodel.Name.getComment.

Returns the comment the user provided when the name was created.

Returns:String

the user comment for this named range

Annotations
@Override
getNameNameback to summary
public String getNameName()

Implements org.apache.poi.ss.usermodel.Name.getNameName.

Doc from org.apache.poi.ss.usermodel.Name.getNameName.

Gets the name of the named range

Returns:String

text name of this defined name

Annotations
@Override
getRefersToFormulaback to summary
public String getRefersToFormula()

Implements org.apache.poi.ss.usermodel.Name.getRefersToFormula.

Doc from org.apache.poi.ss.usermodel.Name.getRefersToFormula.

Returns the formula that the name is defined to refer to.

Returns:String

the reference for this name, null if it has not been set yet. Never empty string

Annotations
@Override
getSheetIndexback to summary
public int getSheetIndex()

Implements org.apache.poi.ss.usermodel.Name.getSheetIndex.

Returns the sheet index this name applies to.

Returns:int

the sheet index this name applies to, -1 if this name applies to the entire workbook

Annotations
@Override
getSheetNameback to summary
public String getSheetName()

Implements org.apache.poi.ss.usermodel.Name.getSheetName.

Get the sheets name which this named range is referenced to

Returns:String

sheet name, which this named range referred to

Annotations
@Override
isDeletedback to summary
public boolean isDeleted()

Implements org.apache.poi.ss.usermodel.Name.isDeleted.

Doc from org.apache.poi.ss.usermodel.Name.isDeleted.

Checks if this name points to a cell that no longer exists

Returns:boolean

true if the name refers to a deleted cell, false otherwise

Annotations
@Override
isFunctionNameback to summary
public boolean isFunctionName()

Implements org.apache.poi.ss.usermodel.Name.isFunctionName.

Checks if this name is a function name

Returns:boolean

true if this name is a function name

Annotations
@Override
isHiddenback to summary
public boolean isHidden()

Implements org.apache.poi.ss.usermodel.Name.isHidden.

Checks if this name is hidden, eg one of the built-in Excel internal names

Returns:boolean

true if this name is a hidden one

Annotations
@Override
setCommentback to summary
public void setComment(String comment)

Implements org.apache.poi.ss.usermodel.Name.setComment.

Sets the comment the user provided when the name was created.

Parameters
comment:String

the user comment for this named range

Annotations
@Override
setFunctionback to summary
public void setFunction(boolean value)

Implements org.apache.poi.ss.usermodel.Name.setFunction.

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.

Parameters
value:boolean

true indicates the name refers to a function.

Annotations
@Override
setNameDefinitionback to summary
pack-priv void setNameDefinition(Ptg[] ptgs)

Sets the NameParsedFormula structure that specifies the formula for the defined name.

Parameters
ptgs:Ptg[]

the sequence of Ptgs for the formula.

setNameNameback to summary
public void setNameName(String nameName)

Implements org.apache.poi.ss.usermodel.Name.setNameName.

Sets the name of the named range

The following is a list of syntax rules that you need to be aware of when you create and edit names.

  • Valid characters The first character of a name must be a letter, an underscore character (_), or a backslash (\). Remaining characters in the name can be letters, numbers, periods, and underscore characters.
  • Cell references disallowed Names cannot be the same as a cell reference, such as Z$100 or R1C1.
  • Spaces are not valid Spaces are not allowed as part of a name. Use the underscore character (_) and period (.) as word separators, such as, Sales_Tax or First.Quarter.
  • Name length A name can contain up to 255 characters.
  • Case sensitivity Names can contain uppercase and lowercase letters.

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
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)"

Parameters
nameName:String

named range name to set

Annotations
@Override
Exceptions
IllegalArgumentException:
if the name is invalid or the name already exists (case-insensitive)
setRefersToFormulaback to summary
public void setRefersToFormula(String formulaText)

Implements org.apache.poi.ss.usermodel.Name.setRefersToFormula.

Doc from org.apache.poi.ss.usermodel.Name.setRefersToFormula.

Sets the formula that the name is defined to refer to. The following are representative examples:

  • '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
Parameters
formulaText:String

the reference for this name

Annotations
@Override
setSheetIndexback to summary
public void setSheetIndex(int index)

Implements org.apache.poi.ss.usermodel.Name.setSheetIndex.

Specifies if the defined name is a local name, and if so, which sheet it is on.

Parameters
index:int

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.

Annotations
@Override
Exceptions
IllegalArgumentException:
if the sheet index is invalid.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

validateNameback to summary
private static void validateName(String name)

https://support.office.com/en-us/article/Define-and-use-names-in-formulas-4D0F13AC-53B7-422E-AFD2-ABD7FF379C64#bmsyntax_rules_for_names Valid characters: First character: { letter | underscore | backslash } Remaining characters: { letter | number | period | underscore } Cell shorthand: cannot be { "C" | "c" | "R" | "r" } Cell references disallowed: cannot be a cell reference $A$1 or R1C1 Spaces are not valid (follows from valid characters above) Name length: (XSSF-specific?) 255 characters maximum Case sensitivity: all names are case-insensitive Uniqueness: must be unique (for names with the same scope)