FDefinedName
| packages | @univerjs/sheets |
|---|
APIs
delete
Deletes the defined name.
Signature
delete(): voidExamples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.delete()getComment
Gets the comment of the defined name.
Signature
getComment(): string | undefinedReturns
- (
string | undefined) — The comment of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
console.log(definedName?.getComment())getFormulaOrRefString
Gets the formula or reference string of the defined name.
Signature
getFormulaOrRefString(): stringReturns
- (
string) — The formula or reference string of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
console.log(definedName?.getFormulaOrRefString())getLocalSheetId
Gets the local sheet id of the defined name.
Signature
getLocalSheetId(): string | undefinedReturns
- (
string | undefined) — The local sheet id of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
console.log(definedName?.getLocalSheetId())getName
Gets the name of the defined name.
Signature
getName(): stringReturns
- (
string) — The name of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
console.log(definedName?.getName())isWorkbookScope
Checks if the defined name is in the workbook scope.
Signature
isWorkbookScope(): booleanReturns
- (
boolean) — True if the defined name is in the workbook scope, false otherwise.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
console.log(definedName?.isWorkbookScope())setComment
Sets the comment of the defined name.
Signature
setComment(comment: string): voidParameters
comment(string) — The comment of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.setComment('This is a comment')setFormula
Sets the formula of the defined name.
Signature
setFormula(formula: string): voidParameters
formula(string) — The formula of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.setFormula('SUM(Sheet1!$A$1)')setHidden
Sets the hidden status of the defined name.
Signature
setHidden(hidden: boolean): voidParameters
hidden(boolean) — The hidden status of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.setHidden(true)setName
Sets the name of the defined name.
Signature
setName(name: string): voidParameters
name(string) — The name of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.setName('NewDefinedName')setRef
Sets the reference of the defined name.
Signature
setRef(refString: string): voidParameters
refString(string) — The reference of the defined name.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.setRef('Sheet1!$A$1')setRefByRange
Sets the reference of the defined name by range.
Signature
setRefByRange(row: number, column: number, numRows: number, numColumns: number): voidParameters
row(number) — The start row of the range.column(number) — The start column of the range.numRows(number) — The number of rows in the range.numColumns(number) — The number of columns in the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.setRefByRange(1, 3, 2, 5) // D2:H3setScopeToWorkbook
Sets the scope of the defined name to the workbook.
Signature
setScopeToWorkbook(): voidExamples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.setScopeToWorkbook()setScopeToWorksheet
Sets the scope of the defined name to the worksheet.
Signature
setScopeToWorksheet(worksheet: FWorksheet): voidParameters
worksheet(FWorksheet) — The worksheet to set the scope to.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const sheets = fWorkbook.getSheets()
// Get the first defined name and make it available only in the second worksheet
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.setScopeToWorksheet(sheets[1])toBuilder
Converts the defined name to a defined name builder.
Signature
toBuilder(): FDefinedNameBuilderReturns
- (
FDefinedNameBuilder) — The defined name builder.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
if (!definedName) return
const definedNameBuilder = definedName
.toBuilder()
.setName('NewDefinedName')
.setFormula('SUM(Sheet1!$A$1)')
.build()
fWorkbook.updateDefinedNameBuilder(definedNameBuilder)