Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Custom, user-defined names are identifiers that represent information in the sheet. A custom name can refer to a range of cells or a formula. You can define a custom name and then use the name in formulas. When the formula is evaluated, the custom name's value is referenced and evaluated. Use the addCustomName method to create a custom name.
Using Code
This example creates a custom name.用户的自定义名称可以用来表示表格中的信息。自定义名称可以指代公式中的一个单元格区域。你可以指定一个自定义名称,并在公式中使用该名称。

当公式求值时,会查找名称的引用并重新求值。使用 addCustomName 方法来创建一个自定义名称。


示例代码
以下代码创建了一个自定义名称。

JavaScript

Copy Code

activeSheet.setValue(0, 0, 1);activeSheet.setValue(0, 1, 2);activeSheet.setValue(0, 2, 3);activeSheet.addCustomName("customName1","=12", 0, 0);activeSheet.addCustomName("customName2","Average(20,45)", 0, 0);activeSheet.addCustomName("customName3", "=$B$1:$C$1", 0, 0);activeSheet.setFormula(1, 0, "customName1");activeSheet.setFormula(1, 1, "customName2");activeSheet.setFormula(1, 2, "sum(customName3)");