Skip to Content
ClassesFDefinedName

类: FDefinedName

继承

  • FBase

方法

delete()

delete(): void;

Deletes the defined name.

返回

void

示例

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

getComment()

getComment(): string;

Gets the comment of the defined name.

返回

string

The comment of the defined name.

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; console.log(definedName?.getComment());

getFormulaOrRefString()

getFormulaOrRefString(): string;

Gets the formula or reference string of the defined name.

返回

string

The formula or reference string of the defined name.

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; console.log(definedName?.getFormulaOrRefString());

getLocalSheetId()

getLocalSheetId(): string;

Gets the local sheet id of the defined name.

返回

string

The local sheet id of the defined name.

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; console.log(definedName?.getLocalSheetId());

getName()

getName(): string;

Gets the name of the defined name.

返回

string

The name of the defined name.

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; console.log(definedName?.getName());

isWorkbookScope()

isWorkbookScope(): boolean;

Checks if the defined name is in the workbook scope.

返回

boolean

True if the defined name is in the workbook scope, false otherwise.

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; console.log(definedName?.isWorkbookScope());

setComment()

setComment(comment): void;

Sets the comment of the defined name.

参数

参数类型描述
commentstringThe comment of the defined name.

返回

void

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; definedName?.setComment('This is a comment');

setFormula()

setFormula(formula): void;

Sets the formula of the defined name.

参数

参数类型描述
formulastringThe formula of the defined name.

返回

void

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; definedName?.setFormula('SUM(Sheet1!$A$1)');

setHidden()

setHidden(hidden): void;

Sets the hidden status of the defined name.

参数

参数类型描述
hiddenbooleanThe hidden status of the defined name.

返回

void

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; definedName?.setHidden(true);

setName()

setName(name): void;

Sets the name of the defined name.

参数

参数类型描述
namestringThe name of the defined name.

返回

void

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; definedName?.setName('NewDefinedName');

setRef()

setRef(refString): void;

Sets the reference of the defined name.

参数

参数类型描述
refStringstringThe reference of the defined name.

返回

void

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; definedName?.setRef('Sheet1!$A$1');

setRefByRange()

setRefByRange( row, column, numRows, numColumns): void;

Sets the reference of the defined name by range.

参数

参数类型描述
rownumberThe start row of the range.
columnnumberThe start column of the range.
numRowsnumberThe number of rows in the range.
numColumnsnumberThe number of columns in the range.

返回

void

示例

const fWorkbook = univerAPI.getActiveWorkbook(); const definedName = fWorkbook.getDefinedNames()[0]; definedName?.setRefByRange(1, 3, 2, 5); // D2:H3

setScopeToWorkbook()

setScopeToWorkbook(): void;

Sets the scope of the defined name to the workbook.

返回

void

示例

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

setScopeToWorksheet()

setScopeToWorksheet(worksheet): void;

Sets the scope of the defined name to the worksheet.

参数

参数类型描述
worksheetFWorksheetThe worksheet to set the scope to.

返回

void

示例

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

toBuilder(): FDefinedNameBuilder;

Converts the defined name to a defined name builder.

返回

FDefinedNameBuilder

The defined name builder.

示例

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