ExcelScript.Workbook interface

Workbook 是包含相关工作簿对象(例如工作表、表和区域)的顶级对象。

注解

示例

/**
 * This script adds a new worksheet to the workbook, then switches to it.
 */
function main(workbook: ExcelScript.Workbook) {
  // Add a new worksheet with the default name.
  let worksheet = workbook.addWorksheet();

  // Switch focus to the new worksheet.
  worksheet.activate();
}

方法

addBinding(range, bindingType, id)

将新的 binding 对象添加到特定区域。

addBindingFromNamedItem(name, bindingType, id)

根据工作簿中的命名项添加新的 binding 对象。 如果命名项引用多个区域, InvalidReference 将返回错误。

addBindingFromSelection(bindingType, id)

根据当前选择的内容添加新的 binding 对象。 如果所选内容有多个区域, InvalidReference 则会返回错误。

addComment(cellAddress, content, contentType)

使用给定单元格上的给定内容创建新批注。 InvalidArgument如果提供的范围大于一个单元格,则会引发错误。

addCustomXmlPart(xml)

向工作簿添加新的自定义 XML 部件。

addNamedItem(name, reference, comment)

将新名称添加到给定范围的集合。

addNamedItemFormulaLocal(name, formula, comment)

使用用户的公式区域设置,将新名称添加到给定范围的集合。

addPivotTable(name, source, destination)

根据指定的源数据添加数据透视表,并将其插入目标区域的左上角单元格。

addPivotTableStyle(name, makeUniqueName)

创建具有指定名称的空白 PivotTableStyle

addPredefinedCellStyle(name)

向集合添加新样式。

addSlicer(slicerSource, sourceField, slicerDestination)

将新切片器添加到工作簿。

addSlicerStyle(name, makeUniqueName)

创建具有指定名称的空白切片器样式。

addTable(address, hasHeaders)

创建一个新表。 范围对象或源地址决定了在哪个工作表下添加表。 如果无法添加表(例如,由于地址无效,或者表与另一个表重叠),则会引发错误。

addTableStyle(name, makeUniqueName)

创建具有指定名称的空白 TableStyle

addTimelineStyle(name, makeUniqueName)

创建具有指定名称的空白 TimelineStyle

addWorksheet(name)

向工作簿添加新工作表。 工作表将添加到现有工作表的末尾。 如果要激活新添加的工作表,请 .activate() 调用它。

breakAllLinksToLinkedWorkbooks()

断开指向链接工作簿的所有链接。 链接断开后,将完全删除引用工作簿链接的所有公式,并将其替换为最近检索的值。

getActiveCell()

获取工作簿中当前处于活动状态的单元格。

getActiveChart()

获取工作簿中的当前活动图表。 如果没有活动图表,则此方法返回 undefined

getActiveSlicer()

获取工作簿中当前处于活动状态的切片器。 如果没有活动切片器,则此方法返回 undefined

getActiveWorksheet()

获取工作簿中当前处于活动状态的工作表。

getApplication()

表示包含此工作簿的 Excel 应用程序实例。

getAutoSave()

指定工作簿是否处于自动保存模式。

getBinding(id)

按 ID 获取绑定对象。 如果绑定对象不存在,则此方法返回 undefined

getBindings()

表示属于工作簿的绑定的集合。

getCalculationEngineVersion()

返回有关 Excel 计算引擎的版本号。

getChartDataPointTrack()

如果工作簿中的所有图表都跟踪它们所附加的实际数据点,则为 True。 如果图表跟踪数据点的索引,则为 False。

getComment(commentId)

根据其 ID 从集合中获取批注。 如果注释对象不存在,则此方法返回 undefined

getCommentByCell(cellAddress)

从指定单元格获取的批注。 如果单元格中没有注释,则会引发错误。

getCommentByReplyId(replyId)

获取给定答复所连接到的注释。

getComments()

表示与工作簿关联的注释的集合。

getCustomXmlPart(id)

获取基于其 ID 的自定义 XML 部件。 CustomXmlPart如果 不存在,则此方法返回 undefined

getCustomXmlPartByNamespace(namespaceUri)

获取其命名空间与给定命名空间匹配的自定义 XML 部件的新集合。

getCustomXmlParts()

表示此工作簿包含的自定义 XML 部件的集合。

getCustomXmlPartsByNamespace(namespaceUri)

获取其命名空间与给定命名空间匹配的自定义 XML 部件的新集合。

getDefaultPivotTableStyle()

获取父对象的作用域的默认数据透视表样式。

getDefaultSlicerStyle()

获取父对象的作用域的默认值 SlicerStyle

getDefaultTableStyle()

获取父对象的作用域的默认表样式。

getDefaultTimelineStyle()

获取父对象的作用域的默认时间线样式。

getFirstWorksheet(visibleOnly)

获取集合中的第一个工作表。

getIsDirty()

指定自上次保存工作簿以来是否进行了更改。 如果要关闭修改的工作簿而不保存它或系统提示保存它,则可以将此属性 true 设置为 。

getLastWorksheet(visibleOnly)

获取集合中的最后一个工作表。

getLinkedWorkbookByUrl(key)

按 URL 获取有关链接工作簿的信息。 如果工作簿不存在,则此方法返回 undefined

getLinkedWorkbookRefreshMode()

表示工作簿链接的更新模式。 该模式对于工作簿中存在的所有工作簿链接都是相同的。

getLinkedWorkbooks()

返回链接工作簿的集合。 在公式中,工作簿链接可用于引用当前工作簿外部) 单元格值和名称 (数据。

getName()

获取工作簿名称。

getNamedItem(name)

NamedItem使用其名称获取对象。 如果该对象不存在,则此方法返回 undefined

getNames()

表示工作簿范围的命名项的集合, () 命名区域和常量。

getPivotTable(name)

按名称获取 PivotTable 对象。 如果数据透视表不存在,则此方法返回 undefined

getPivotTables()

表示一组与 workbook 相关联的 PivotTable 对象。

getPivotTableStyle(name)

PivotTableStyle按名称获取 。 PivotTableStyle如果 不存在,则此方法返回 undefined

getPivotTableStyles()

表示一组与工作簿相关联的 PivotTableStyles。

getPredefinedCellStyle(name)

按名称获取样式。 如果样式对象不存在,则此方法返回 undefined

getPredefinedCellStyles()

表示与工作簿关联的样式的集合。

getPreviouslySaved()

指定工作簿是在本地保存还是联机保存。

getProperties()

获取工作簿属性。

getProtection()

返回工作簿的保护对象。

getQueries()

返回属于工作簿的 Power Query 查询的集合。

getQuery(key)

根据集合的名称从集合中获取查询。

getReadOnly()

true如果工作簿在只读模式下打开,则返回 。

getSelectedRange()

从工作簿中获取当前选定的单个区域。 如果选择了多个范围,此方法将引发错误。

getSelectedRanges()

从工作簿中获取当前选定的一个或多个区域。 与 不同 getSelectedRange(),此方法返回一个 RangeAreas 对象,该对象表示所有选定区域。

getSlicer(key)

使用切片器的名称或 ID 获取切片器。 如果切片器不存在,则此方法返回 undefined

getSlicers()

表示与工作簿关联的切片器的集合。

getSlicerStyle(name)

SlicerStyle按名称获取 。 如果切片器样式不存在,则此方法返回 undefined

getSlicerStyles()

表示一组与工作簿相关联的 SlicerStyles。

getTable(key)

按名称或 ID 获取表。 如果该表不存在,则此方法返回 undefined

getTables()

表示与工作簿关联的表的集合。

getTableStyle(name)

TableStyle按名称获取 。 如果表样式不存在,则此方法返回 undefined

getTableStyles()

表示一组与工作簿相关联的 TableStyles。

getTimelineStyle(name)

TimelineStyle按名称获取 。 如果时间线样式不存在,则此方法返回 undefined

getTimelineStyles()

表示一组与工作簿相关联的 TimelineStyles。

getUsePrecisionAsDisplayed()

如果此工作簿中的计算仅使用显示的数字精度来完成,则为 True。 将此属性从 falsetrue切换到 时,数据将永久失去准确性。

getWorksheet(key)

使用其名称或 ID 获取 worksheet 对象。 如果工作表不存在,则此方法返回 undefined

getWorksheets()

表示与工作簿关联的工作表的集合。

refreshAllDataConnections()

刷新所有数据连接。

refreshAllLinksToLinkedWorkbooks()

发出刷新所有工作簿链接的请求。

refreshAllPivotTables()

刷新集合中的所有数据透视表。

setChartDataPointTrack(chartDataPointTrack)

如果工作簿中的所有图表都跟踪它们所附加的实际数据点,则为 True。 如果图表跟踪数据点的索引,则为 False。

setDefaultPivotTableStyle(newDefaultStyle)

设置在父对象的作用域中使用的默认数据透视表样式。

setDefaultSlicerStyle(newDefaultStyle)

设置在父对象的作用域中使用的默认切片器样式。

setDefaultTableStyle(newDefaultStyle)

设置在父对象的作用域中使用的默认表样式。

setDefaultTimelineStyle(newDefaultStyle)

设置在父对象的作用域中使用的默认时间线样式。

setIsDirty(isDirty)

指定自上次保存工作簿以来是否进行了更改。 如果要关闭修改的工作簿而不保存它或系统提示保存它,则可以将此属性 true 设置为 。

setLinkedWorkbookRefreshMode(linkedWorkbookRefreshMode)

表示工作簿链接的更新模式。 该模式对于工作簿中存在的所有工作簿链接都是相同的。

setUsePrecisionAsDisplayed(usePrecisionAsDisplayed)

如果此工作簿中的计算仅使用显示的数字精度来完成,则为 True。 将此属性从 falsetrue切换到 时,数据将永久失去准确性。

方法详细信息

addBinding(range, bindingType, id)

将新的 binding 对象添加到特定区域。

addBinding(
            range: Range | string,
            bindingType: BindingType,
            id: string
        ): Binding;

参数

range

ExcelScript.Range | string

要将绑定绑定到的范围。 可以是 Range 对象或字符串。 如果是字符串,必须包含完整地址,包括工作表名称

bindingType
ExcelScript.BindingType

绑定的类型。 请参阅 ExcelScript.BindingType

id

string

绑定的名称。

返回

addBindingFromNamedItem(name, bindingType, id)

根据工作簿中的命名项添加新的 binding 对象。 如果命名项引用多个区域, InvalidReference 将返回错误。

addBindingFromNamedItem(
            name: string,
            bindingType: BindingType,
            id: string
        ): Binding;

参数

name

string

从中创建绑定的名称。

bindingType
ExcelScript.BindingType

绑定的类型。 请参阅 ExcelScript.BindingType

id

string

绑定的名称。

返回

addBindingFromSelection(bindingType, id)

根据当前选择的内容添加新的 binding 对象。 如果所选内容有多个区域, InvalidReference 则会返回错误。

addBindingFromSelection(bindingType: BindingType, id: string): Binding;

参数

bindingType
ExcelScript.BindingType

绑定的类型。 请参阅 ExcelScript.BindingType

id

string

绑定的名称。

返回

addComment(cellAddress, content, contentType)

使用给定单元格上的给定内容创建新批注。 InvalidArgument如果提供的范围大于一个单元格,则会引发错误。

addComment(
            cellAddress: Range | string,
            content: CommentRichContent | string,
            contentType?: ContentType
        ): Comment;

参数

cellAddress

ExcelScript.Range | string

要向其添加注释的单元格。 这可以是 Range 对象或字符串。 如果是字符串,则必须包含完整地址,包括工作表名称。 InvalidArgument如果提供的范围大于一个单元格,则会引发错误。

content

ExcelScript.CommentRichContent | string

批注的内容。 这可以是字符串或 CommentRichContent 对象。 字符串用于纯文本。 CommentRichContent 对象允许使用其他注释功能,例如提及。

contentType
ExcelScript.ContentType

可选。 批注中包含的内容类型。 默认值为 enum ContentType.Plain

返回

addCustomXmlPart(xml)

向工作簿添加新的自定义 XML 部件。

addCustomXmlPart(xml: string): CustomXmlPart;

参数

xml

string

XML 内容。 必须是有效的 XML 片段。

返回

addNamedItem(name, reference, comment)

将新名称添加到给定范围的集合。

addNamedItem(
            name: string,
            reference: Range | string,
            comment?: string
        ): NamedItem;

参数

name

string

已命名项目的名称。

reference

ExcelScript.Range | string

名称将引用的公式或区域。

comment

string

可选。 与命名项关联的注释。

返回

示例

/**
 * This script creates a named formula and uses it in another part of the workbook.
 */
function main(workbook: ExcelScript.Workbook) {
  // Create a named item for a formula.
  // This formula is the sum of the cells F2:F21 on Sheet1.
  const namedItem: ExcelScript.NamedItem = workbook.addNamedItem(
    "GrandTotal", 
    "=SUM(Sheet1!$F$2:$F$21)", 
    "The sum of table sums."
  );

  // Add this named formula to a new sheet in the workbook.
  const otherSheet = workbook.addWorksheet();
  otherSheet.getRange("A1").setFormula(namedItem.getFormula());

  // Switch to the new worksheet.
  otherSheet.activate();
}

addNamedItemFormulaLocal(name, formula, comment)

使用用户的公式区域设置,将新名称添加到给定范围的集合。

addNamedItemFormulaLocal(
            name: string,
            formula: string,
            comment?: string
        ): NamedItem;

参数

name

string

已命名项目的名称。

formula

string

名称将引用的采用用户区域设置的公式。

comment

string

可选。 与命名项关联的注释。

返回

addPivotTable(name, source, destination)

根据指定的源数据添加数据透视表,并将其插入目标区域的左上角单元格。

addPivotTable(
            name: string,
            source: Range | string | Table,
            destination: Range | string
        ): PivotTable;

参数

name

string

新数据透视表的名称。

source

ExcelScript.Range | string | ExcelScript.Table

新数据透视表的源数据可以是区域 (,也可以是字符串地址,包括工作表名称) 或表格。

destination

ExcelScript.Range | string

数据透视表目标区域(工作表中用于放置所生成的报表的区域)左上角的单元格。

返回

示例

/**
 * This script creates a PivotTable from an existing table and adds it to an existing worksheet.
 * This script assumes there is a table in the current worksheet with columns named "Type" and "Sales".
 * It also assumes there is a worksheet named "PivotSheet".
 */
function main(workbook: ExcelScript.Workbook) {
  // Create a PivotTable based on a table in the current worksheet.
  let sheet = workbook.getActiveWorksheet();
  let table = sheet.getTables()[0];
  let pivotTable = workbook.addPivotTable("My Pivot", table, "PivotSheet!A1");

  // Add fields to the PivotTable to show "Sales" per "Type".
  pivotTable.addRowHierarchy(pivotTable.getHierarchy("Type"));
  pivotTable.addDataHierarchy(pivotTable.getHierarchy("Sales"));
}

addPivotTableStyle(name, makeUniqueName)

创建具有指定名称的空白 PivotTableStyle

addPivotTableStyle(
            name: string,
            makeUniqueName?: boolean
        ): PivotTableStyle;

参数

name

string

新数据透视表样式的唯一名称。 如果名称已在使用中,将引发 InvalidArgument 错误。

makeUniqueName

boolean

可选。 默认为 false。 如果 true为 ,则会在名称中追加数字,以便在需要时使其唯一。

返回

addPredefinedCellStyle(name)

向集合添加新样式。

addPredefinedCellStyle(name: string): void;

参数

name

string

要添加的样式的名称。

返回

void

addSlicer(slicerSource, sourceField, slicerDestination)

将新切片器添加到工作簿。

addSlicer(
            slicerSource: string | PivotTable | Table,
            sourceField: string | PivotField | number | TableColumn,
            slicerDestination?: string | Worksheet
        ): Slicer;

参数

slicerSource

string | ExcelScript.PivotTable | ExcelScript.Table

新切片器将基于的数据源。 它可以是 PivotTable 对象、 Table 对象或字符串。 传递数据透视表对象时,数据源是该 PivotTable 对象的源。 Table传递对象时,数据源为 Table 对象。 传递字符串时,它将解释为数据透视表或表的名称或 ID。

sourceField

string | ExcelScript.PivotField | number | ExcelScript.TableColumn

数据源中要筛选的字段。 它可以是 对象、TableColumn对象、的 PivotField ID 或 的名称或 IDTableColumnPivotField

slicerDestination

string | ExcelScript.Worksheet

可选。 将在其中创建新切片器的工作表。 它可以是 Worksheet 对象,也可以是工作表的名称或 ID。 如果从工作表检索切片器集合,则可以省略此参数。

返回

示例

/**
 * This script adds a slicer for an existing PivotTable.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the PivotTable named "Farm Pivot".
  const farmPivot = workbook.getPivotTable("Farm Pivot");

  // Create the slicer. 
  // Note that this assumes "Type" is already added as a hierarchy to the PivotTable.
  const fruitSlicer: ExcelScript.Slicer = workbook.addSlicer(
    farmPivot, /* The table or PivotTale to be sliced. */
    farmPivot.getHierarchy("Type").getFields()[0] /* What source field to use as the slicer options. */
  );

  // Select the items to display.
  fruitSlicer.selectItems(["Lemon", "Lime"]);

  // Set the left margin of the slicer.
  fruitSlicer.setLeft(400);
}

addSlicerStyle(name, makeUniqueName)

创建具有指定名称的空白切片器样式。

addSlicerStyle(name: string, makeUniqueName?: boolean): SlicerStyle;

参数

name

string

新切片器样式的唯一名称。 如果名称已在使用中,将引发 InvalidArgument 异常。

makeUniqueName

boolean

可选。 默认为 false。 如果 true为 ,则会在名称中追加数字,以便在需要时使其唯一。

返回

addTable(address, hasHeaders)

创建一个新表。 范围对象或源地址决定了在哪个工作表下添加表。 如果无法添加表(例如,由于地址无效,或者表与另一个表重叠),则会引发错误。

addTable(address: Range | string, hasHeaders: boolean): Table;

参数

address

ExcelScript.Range | string

对象 Range ,或表示数据源的区域的字符串地址或名称。 如果地址不包含工作表名称,将使用当前活动的工作表。

hasHeaders

boolean

一个布尔值,指示导入的数据是否具有列标签。 如果源不包含标头 (即当此属性设置为 false) 时,Excel 将自动生成一个标题,并将数据向下移动一行。

返回

示例

/**
 * This sample converts the information in the first worksheet
 * into a table with headers.
*/
function main(workbook: ExcelScript.Workbook) {
  // This assumes there is one contiguous range in the first worksheet.
  const dataRange = workbook.getFirstWorksheet().getUsedRange();
  
  // Add a table at the workbook level.
  workbook.addTable(dataRange.getAddress(), true);
}

addTableStyle(name, makeUniqueName)

创建具有指定名称的空白 TableStyle

addTableStyle(name: string, makeUniqueName?: boolean): TableStyle;

参数

name

string

新表格样式的唯一名称。 如果名称已在使用中,将引发 InvalidArgument 错误。

makeUniqueName

boolean

可选。 默认为 false。 如果 true为 ,则会在名称中追加数字,以便在需要时使其唯一。

返回

addTimelineStyle(name, makeUniqueName)

创建具有指定名称的空白 TimelineStyle

addTimelineStyle(name: string, makeUniqueName?: boolean): TimelineStyle;

参数

name

string

新时间线样式的唯一名称。 如果名称已在使用中,将引发 InvalidArgument 错误。

makeUniqueName

boolean

可选。 默认为 false。 如果 true为 ,则会在名称中追加数字,以便在需要时使其唯一。

返回

addWorksheet(name)

向工作簿添加新工作表。 工作表将添加到现有工作表的末尾。 如果要激活新添加的工作表,请 .activate() 调用它。

addWorksheet(name?: string): Worksheet;

参数

name

string

可选。 要添加的工作表的名称。 如果指定,名称应是唯一的。 如果未指定,Excel 将确定新工作表的名称。

返回

示例

/**
 * This script adds a new worksheet named "Data" to the workbook.
 * If a worksheet with that name already exists, the script logs a note.
 */
function main(workbook: ExcelScript.Workbook) {
  // Check if the "Data" worksheet already exists.
  if (workbook.getWorksheet("Data")) {
    console.log("The Data worksheet is already in the workbook.");
  } else {
    // Add a new worksheet.
    let worksheet = workbook.addWorksheet("Data");
  }
}

breakAllLinksToLinkedWorkbooks()

断开指向链接工作簿的所有链接。 链接断开后,将完全删除引用工作簿链接的所有公式,并将其替换为最近检索的值。

breakAllLinksToLinkedWorkbooks(): void;

返回

void

getActiveCell()

获取工作簿中当前处于活动状态的单元格。

getActiveCell(): Range;

返回

示例

/**
 * This script logs the value of the current active cell. 
 * If multiple cells are selected, the top-leftmost cell will be logged.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the current active cell in the workbook.
  let cell = workbook.getActiveCell();
  console.log(`The current cell's value is ${cell.getValue()}`);
}

getActiveChart()

获取工作簿中的当前活动图表。 如果没有活动图表,则此方法返回 undefined

getActiveChart(): Chart;

返回

getActiveSlicer()

获取工作簿中当前处于活动状态的切片器。 如果没有活动切片器,则此方法返回 undefined

getActiveSlicer(): Slicer;

返回

getActiveWorksheet()

获取工作簿中当前处于活动状态的工作表。

getActiveWorksheet(): Worksheet;

返回

getApplication()

表示包含此工作簿的 Excel 应用程序实例。

getApplication(): Application;

返回

getAutoSave()

指定工作簿是否处于自动保存模式。

getAutoSave(): boolean;

返回

boolean

getBinding(id)

按 ID 获取绑定对象。 如果绑定对象不存在,则此方法返回 undefined

getBinding(id: string): Binding | undefined;

参数

id

string

要检索的绑定对象的 ID。

返回

ExcelScript.Binding | undefined

getBindings()

表示属于工作簿的绑定的集合。

getBindings(): Binding[];

返回

getCalculationEngineVersion()

返回有关 Excel 计算引擎的版本号。

getCalculationEngineVersion(): number;

返回

number

getChartDataPointTrack()

如果工作簿中的所有图表都跟踪它们所附加的实际数据点,则为 True。 如果图表跟踪数据点的索引,则为 False。

getChartDataPointTrack(): boolean;

返回

boolean

getComment(commentId)

根据其 ID 从集合中获取批注。 如果注释对象不存在,则此方法返回 undefined

getComment(commentId: string): Comment | undefined;

参数

commentId

string

注释的标识符。

返回

ExcelScript.Comment | undefined

getCommentByCell(cellAddress)

从指定单元格获取的批注。 如果单元格中没有注释,则会引发错误。

getCommentByCell(cellAddress: Range | string): Comment;

参数

cellAddress

ExcelScript.Range | string

注释所在的单元格。 这可以是 Range 对象或字符串。 如果是字符串,则必须包含完整地址,包括工作表名称。 InvalidArgument如果提供的范围大于一个单元格,则会引发错误。

返回

getCommentByReplyId(replyId)

获取给定答复所连接到的注释。

getCommentByReplyId(replyId: string): Comment;

参数

replyId

string

批注回复的标识符。

返回

getComments()

表示与工作簿关联的注释的集合。

getComments(): Comment[];

返回

getCustomXmlPart(id)

获取基于其 ID 的自定义 XML 部件。 CustomXmlPart如果 不存在,则此方法返回 undefined

getCustomXmlPart(id: string): CustomXmlPart | undefined;

参数

id

string

要检索的对象 ID。

返回

getCustomXmlPartByNamespace(namespaceUri)

警告

现已弃用此 API。

Use getCustomXmlPartsByNamespace instead.

获取其命名空间与给定命名空间匹配的自定义 XML 部件的新集合。

getCustomXmlPartByNamespace(namespaceUri: string): CustomXmlPart[];

参数

namespaceUri

string

这必须是完全限定的架构 URI;例如,“http://schemas.contoso.com/review/1.0"。

返回

getCustomXmlParts()

表示此工作簿包含的自定义 XML 部件的集合。

getCustomXmlParts(): CustomXmlPart[];

返回

getCustomXmlPartsByNamespace(namespaceUri)

获取其命名空间与给定命名空间匹配的自定义 XML 部件的新集合。

getCustomXmlPartsByNamespace(namespaceUri: string): CustomXmlPart[];

参数

namespaceUri

string

这必须是完全限定的架构 URI;例如,“http://schemas.contoso.com/review/1.0"。

返回

getDefaultPivotTableStyle()

获取父对象的作用域的默认数据透视表样式。

getDefaultPivotTableStyle(): PivotTableStyle;

返回

getDefaultSlicerStyle()

获取父对象的作用域的默认值 SlicerStyle

getDefaultSlicerStyle(): SlicerStyle;

返回

getDefaultTableStyle()

获取父对象的作用域的默认表样式。

getDefaultTableStyle(): TableStyle;

返回

getDefaultTimelineStyle()

获取父对象的作用域的默认时间线样式。

getDefaultTimelineStyle(): TimelineStyle;

返回

getFirstWorksheet(visibleOnly)

获取集合中的第一个工作表。

getFirstWorksheet(visibleOnly?: boolean): Worksheet;

参数

visibleOnly

boolean

可选。 如果 true为 ,则仅考虑可见工作表,跳过任何隐藏工作表。

返回

getIsDirty()

指定自上次保存工作簿以来是否进行了更改。 如果要关闭修改的工作簿而不保存它或系统提示保存它,则可以将此属性 true 设置为 。

getIsDirty(): boolean;

返回

boolean

getLastWorksheet(visibleOnly)

获取集合中的最后一个工作表。

getLastWorksheet(visibleOnly?: boolean): Worksheet;

参数

visibleOnly

boolean

可选。 如果 true为 ,则仅考虑可见工作表,跳过任何隐藏工作表。

返回

getLinkedWorkbookByUrl(key)

按 URL 获取有关链接工作簿的信息。 如果工作簿不存在,则此方法返回 undefined

getLinkedWorkbookByUrl(key: string): LinkedWorkbook | undefined;

参数

key

string

链接工作簿的 URL。

返回

getLinkedWorkbookRefreshMode()

表示工作簿链接的更新模式。 该模式对于工作簿中存在的所有工作簿链接都是相同的。

getLinkedWorkbookRefreshMode(): WorkbookLinksRefreshMode;

返回

示例

/**
 * This script refreshes all the links to external workbooks, 
 * if the linked workbook refresh mode is set to manual.
 * To learn about linked workbooks, see https://support.microsoft.com/office/c98d1803-dd75-4668-ac6a-d7cca2a9b95f.
 */
function main(workbook: ExcelScript.Workbook) {
  // Check the refresh mode.
  if (workbook.getLinkedWorkbookRefreshMode() === ExcelScript.WorkbookLinksRefreshMode.manual) {
    console.log("Refreshing workbook links");

    // Trigger a refresh of linked workbook content.
    workbook.refreshAllLinksToLinkedWorkbooks();
  }

getLinkedWorkbooks()

返回链接工作簿的集合。 在公式中,工作簿链接可用于引用当前工作簿外部) 单元格值和名称 (数据。

getLinkedWorkbooks(): LinkedWorkbook[];

返回

示例

/**
 * This script removes all links to other workbooks.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get all the linked workbook references.
    const externalWorkbooks: ExcelScript.LinkedWorkbook[] = workbook.getLinkedWorkbooks();
    console.log(`There are ${externalWorkbooks.length} other workbooks linked to from this workbook.`);

    // Remove all the links to those workbooks.
    // This changes the value of cells with workbook links to "#CONNECT!".
    externalWorkbooks.forEach((workbookLink) => {
        workbookLink.breakLinks();
    });
}

getName()

获取工作簿名称。

getName(): string;

返回

string

示例

/**
 * This script logs the name of the workbook without the ".xlsx" extension.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the workbook's name.
  let name = workbook.getName();

  // Remove the file extension.
  name = name.substring(0, name.lastIndexOf(".xlsx"));

  // Display the name in the console.
  console.log(name);
}

getNamedItem(name)

NamedItem使用其名称获取对象。 如果该对象不存在,则此方法返回 undefined

getNamedItem(name: string): NamedItem | undefined;

参数

name

string

Nameditem name。

返回

ExcelScript.NamedItem | undefined

getNames()

表示工作簿范围的命名项的集合, () 命名区域和常量。

getNames(): NamedItem[];

返回

示例

/**
 * This script looks for every named range with "Review" in the name 
 * and marks the range with a yellow fill.
 */
function main(workbook: ExcelScript.Workbook) {
  // Look at every named item in the workbook.
  workbook.getNames().forEach((namedItem) => {
    // Find names containing "Review".
    if (namedItem.getName().includes("Review")) {
      // Only change the fill color if the named item is a range (not a formula).
      let itemType: ExcelScript.NamedItemType = namedItem.getType();
      if (itemType === ExcelScript.NamedItemType.range) {
        // Set the range's fill color to yellow.
        namedItem.getRange().getFormat().getFill().setColor("yellow");
      }
    }
  });
}

getPivotTable(name)

按名称获取 PivotTable 对象。 如果数据透视表不存在,则此方法返回 undefined

getPivotTable(name: string): PivotTable | undefined;

参数

name

string

要检索的数据透视表的名称。

返回

getPivotTables()

表示一组与 workbook 相关联的 PivotTable 对象。

getPivotTables(): PivotTable[];

返回

getPivotTableStyle(name)

PivotTableStyle按名称获取 。 PivotTableStyle如果 不存在,则此方法返回 undefined

getPivotTableStyle(name: string): PivotTableStyle | undefined;

参数

name

string

要检索的数据透视表样式的名称。

返回

getPivotTableStyles()

表示一组与工作簿相关联的 PivotTableStyles。

getPivotTableStyles(): PivotTableStyle[];

返回

getPredefinedCellStyle(name)

按名称获取样式。 如果样式对象不存在,则此方法返回 undefined

getPredefinedCellStyle(name: string): PredefinedCellStyle | undefined;

参数

name

string

要检索的样式的名称。

返回

getPredefinedCellStyles()

表示与工作簿关联的样式的集合。

getPredefinedCellStyles(): PredefinedCellStyle[];

返回

getPreviouslySaved()

指定工作簿是在本地保存还是联机保存。

getPreviouslySaved(): boolean;

返回

boolean

getProperties()

获取工作簿属性。

getProperties(): DocumentProperties;

返回

getProtection()

返回工作簿的保护对象。

getProtection(): WorkbookProtection;

返回

示例

/**
 * This script protects the workbook with a password, if it isn't already protected.
 * The password is provided by the user through a prompt.
 */
function main(workbook: ExcelScript.Workbook, password?: string) {
  // Get the workbook-level protection object.
  const protection = workbook.getProtection();

  // Check if the workbook is already protected.
  if (!protection.getProtected()) {
      // Protect the workbook with the given password.
      // If the optional password was omitted, 
      // no password will be needed to unprotect the workbook.
    protection.protect(password);
  }
}

getQueries()

返回属于工作簿的 Power Query 查询的集合。

getQueries(): Query[];

返回

getQuery(key)

根据集合的名称从集合中获取查询。

getQuery(key: string): Query;

参数

key

string

不区分大小写的查询的名称。

返回

getReadOnly()

true如果工作簿在只读模式下打开,则返回 。

getReadOnly(): boolean;

返回

boolean

getSelectedRange()

从工作簿中获取当前选定的单个区域。 如果选择了多个范围,此方法将引发错误。

getSelectedRange(): Range;

返回

getSelectedRanges()

从工作簿中获取当前选定的一个或多个区域。 与 不同 getSelectedRange(),此方法返回一个 RangeAreas 对象,该对象表示所有选定区域。

getSelectedRanges(): RangeAreas;

返回

getSlicer(key)

使用切片器的名称或 ID 获取切片器。 如果切片器不存在,则此方法返回 undefined

getSlicer(key: string): Slicer | undefined;

参数

key

string

要检索的切片器的名称或 ID。

返回

ExcelScript.Slicer | undefined

getSlicers()

表示与工作簿关联的切片器的集合。

getSlicers(): Slicer[];

返回

getSlicerStyle(name)

SlicerStyle按名称获取 。 如果切片器样式不存在,则此方法返回 undefined

getSlicerStyle(name: string): SlicerStyle | undefined;

参数

name

string

要检索的切片器样式的名称。

返回

getSlicerStyles()

表示一组与工作簿相关联的 SlicerStyles。

getSlicerStyles(): SlicerStyle[];

返回

getTable(key)

按名称或 ID 获取表。 如果该表不存在,则此方法返回 undefined

getTable(key: string): Table | undefined;

参数

key

string

要检索的表的名称或 ID。

返回

ExcelScript.Table | undefined

getTables()

表示与工作簿关联的表的集合。

getTables(): Table[];

返回

getTableStyle(name)

TableStyle按名称获取 。 如果表样式不存在,则此方法返回 undefined

getTableStyle(name: string): TableStyle | undefined;

参数

name

string

要检索的表样式的名称。

返回

getTableStyles()

表示一组与工作簿相关联的 TableStyles。

getTableStyles(): TableStyle[];

返回

getTimelineStyle(name)

TimelineStyle按名称获取 。 如果时间线样式不存在,则此方法返回 undefined

getTimelineStyle(name: string): TimelineStyle | undefined;

参数

name

string

要检索的时间线样式的名称。

返回

getTimelineStyles()

表示一组与工作簿相关联的 TimelineStyles。

getTimelineStyles(): TimelineStyle[];

返回

getUsePrecisionAsDisplayed()

如果此工作簿中的计算仅使用显示的数字精度来完成,则为 True。 将此属性从 falsetrue切换到 时,数据将永久失去准确性。

getUsePrecisionAsDisplayed(): boolean;

返回

boolean

getWorksheet(key)

使用其名称或 ID 获取 worksheet 对象。 如果工作表不存在,则此方法返回 undefined

getWorksheet(key: string): Worksheet | undefined;

参数

key

string

工作表的名称或 ID。

返回

ExcelScript.Worksheet | undefined

示例

/**
 * This script switches the active view to a worksheet named "Data", if it exists.
 */
function main(workbook: ExcelScript.Workbook) {
  // Check if the "Data" worksheet exists.
  let dataWorksheet = workbook.getWorksheet("Data");
  if (dataWorksheet) {
    // Switch to the "Data" worksheet.
    dataWorksheet.activate();
  } else {
    console.log(`No worksheet named "Data" in this workbook.`);
  }
}

getWorksheets()

表示与工作簿关联的工作表的集合。

getWorksheets(): Worksheet[];

返回

示例

/**
 * This script logs the names of all the worksheets in the workbook.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get all the worksheets in the workbook. 
  let sheets = workbook.getWorksheets();

  // Get a list of all the worksheet names.
  let names = sheets.map ((sheet) => sheet.getName());

  // Write in the console all the worksheet names and the total count.
  console.log(names);
  console.log(`Total worksheets inside of this workbook: ${sheets.length}`);
}

refreshAllDataConnections()

刷新所有数据连接。

refreshAllDataConnections(): void;

返回

void

refreshAllLinksToLinkedWorkbooks()

发出刷新所有工作簿链接的请求。

refreshAllLinksToLinkedWorkbooks(): void;

返回

void

refreshAllPivotTables()

刷新集合中的所有数据透视表。

refreshAllPivotTables(): void;

返回

void

setChartDataPointTrack(chartDataPointTrack)

如果工作簿中的所有图表都跟踪它们所附加的实际数据点,则为 True。 如果图表跟踪数据点的索引,则为 False。

setChartDataPointTrack(chartDataPointTrack: boolean): void;

参数

chartDataPointTrack

boolean

返回

void

setDefaultPivotTableStyle(newDefaultStyle)

设置在父对象的作用域中使用的默认数据透视表样式。

setDefaultPivotTableStyle(
            newDefaultStyle: PivotTableStyle | string
        ): void;

参数

newDefaultStyle

ExcelScript.PivotTableStyle | string

PivotTableStyle 为新默认值的对象 PivotTableStyle 或对象的名称。

返回

void

setDefaultSlicerStyle(newDefaultStyle)

设置在父对象的作用域中使用的默认切片器样式。

setDefaultSlicerStyle(newDefaultStyle: SlicerStyle | string): void;

参数

newDefaultStyle

ExcelScript.SlicerStyle | string

SlicerStyle 为新默认值的对象 SlicerStyle 或对象的名称。

返回

void

setDefaultTableStyle(newDefaultStyle)

设置在父对象的作用域中使用的默认表样式。

setDefaultTableStyle(newDefaultStyle: TableStyle | string): void;

参数

newDefaultStyle

ExcelScript.TableStyle | string

TableStyle 为新默认值的对象 TableStyle 或对象的名称。

返回

void

setDefaultTimelineStyle(newDefaultStyle)

设置在父对象的作用域中使用的默认时间线样式。

setDefaultTimelineStyle(newDefaultStyle: TimelineStyle | string): void;

参数

newDefaultStyle

ExcelScript.TimelineStyle | string

TimelineStyle 为新默认值的对象 TimelineStyle 或对象的名称。

返回

void

setIsDirty(isDirty)

指定自上次保存工作簿以来是否进行了更改。 如果要关闭修改的工作簿而不保存它或系统提示保存它,则可以将此属性 true 设置为 。

setIsDirty(isDirty: boolean): void;

参数

isDirty

boolean

返回

void

setLinkedWorkbookRefreshMode(linkedWorkbookRefreshMode)

表示工作簿链接的更新模式。 该模式对于工作簿中存在的所有工作簿链接都是相同的。

setLinkedWorkbookRefreshMode(
            linkedWorkbookRefreshMode: WorkbookLinksRefreshMode
        ): void;

参数

linkedWorkbookRefreshMode
ExcelScript.WorkbookLinksRefreshMode

返回

void

setUsePrecisionAsDisplayed(usePrecisionAsDisplayed)

如果此工作簿中的计算仅使用显示的数字精度来完成,则为 True。 将此属性从 falsetrue切换到 时,数据将永久失去准确性。

setUsePrecisionAsDisplayed(usePrecisionAsDisplayed: boolean): void;

参数

usePrecisionAsDisplayed

boolean

返回

void