FDefinedName

GitHubEdit on GitHub
packages@univerjs/sheets

APIs

delete

Deletes the defined name.

Signature

delete(): void

Examples

const fWorkbook = univerAPI.getActiveWorkbook()
const definedName = fWorkbook.getDefinedNames()[0]
definedName?.delete()

getComment

Gets the comment of the defined name.

Signature

getComment(): string | undefined

Returns

  • (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(): string

Returns

  • (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 | undefined

Returns

  • (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(): string

Returns

  • (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(): boolean

Returns

  • (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): void

Parameters

  • 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): void

Parameters

  • 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): void

Parameters

  • 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): void

Parameters

  • 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): void

Parameters

  • 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): void

Parameters

  • 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:H3

setScopeToWorkbook

Sets the scope of the defined name to the workbook.

Signature

setScopeToWorkbook(): void

Examples

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): void

Parameters

  • 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(): FDefinedNameBuilder

Returns

  • (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)