Excel.Worksheet class

Excel 工作表是由单元格组成的网格。An Excel worksheet is a grid of cells. 它可以包含数据、表、图表等。It can contain data, tables, charts, etc.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

Extends

属性

autoFilter

表示工作表的 AutoFilter 对象。Represents the AutoFilter object of the worksheet. 只读。Read-Only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

charts

返回属于工作表的图表的集合。Returns collection of charts that are part of the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

comments

返回工作表上的所有 Comments 对象的集合。Returns a collection of all the Comments objects on the worksheet. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

context

与该对象关联的请求上下文。The request context associated with the object. 这会将加载项的进程连接到 Office 主机应用程序的进程。This connects the add-in's process to the Office host application's process.

enableCalculation

获取或设置工作表的 enableCalculation 属性。Gets or sets the enableCalculation property of the worksheet. 如此如果 Excel 根据需要重新计算工作表。True if Excel recalculates the worksheet when necessary. 如果 Excel 不重新计算工作表,则该值为 False。False if Excel doesn't recalculate the sheet.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

freezePanes

获取一个对象, 该对象可用于操作工作表上的冻结窗格。Gets an object that can be used to manipulate frozen panes on the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

horizontalPageBreaks

获取工作表的水平分页符集合。Gets the horizontal page break collection for the worksheet. 此集合仅包含手动分页符。This collection only contains manual page breaks.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

id

返回用于唯一标识指定工作簿中工作表的值。即使工作表被重命名或移动,标识符的值仍然相同。只读。Returns a value that uniquely identifies the worksheet in a given workbook. The value of the identifier remains the same even when the worksheet is renamed or moved. Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

name

工作表的显示名称。The display name of the worksheet.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

names

一组范围限定到当前工作表的名称。Collection of names scoped to the current worksheet. 只读。Read-only.

[API 集: ExcelApi 1.4][ API set: ExcelApi 1.4 ]

pageLayout

获取工作表的 PageLayout 对象。Gets the PageLayout object of the worksheet.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

pivotTables

一组属于 worksheet 的 PivotTable 对象。Collection of PivotTables that are part of the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

position

工作表在工作簿中的位置,从零开始。The zero-based position of the worksheet within the workbook.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

protection

返回表工作表的工作表保护对象。Returns sheet protection object for a worksheet. 只读。Read-only.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

shapes

返回工作表上的所有 Shape 对象的集合。Returns the collection of all the Shape objects on the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

showGridlines

获取或设置工作表的网格线标志。Gets or sets the worksheet's gridlines flag. 此标志确定是否对用户显示网格线。This flag determines whether gridlines are visible to the user.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

showHeadings

获取或设置工作表的标题标志。Gets or sets the worksheet's headings flag. 此标志确定是否对用户显示标题。This flag determines whether headings are visible to the user.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

slicers

返回作为工作表一部分的切片器集合。Returns collection of slicers that are part of the worksheet. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

standardHeight

返回工作表中所有行的标准(默认)行高,以磅为单位。Returns the standard (default) height of all the rows in the worksheet, in points. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

standardWidth

返回或设置工作表中所有列的标准(默认)列宽。Returns or sets the standard (default) width of all the columns in the worksheet. 一个列宽单位等于“常规”样式中一个字符的宽度。One unit of column width is equal to the width of one character in the Normal style. 对于比例字体,则使用字符 0(零)的宽度。For proportional fonts, the width of the character 0 (zero) is used.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

tabColor

获取或设置工作表标签颜色。Gets or sets the worksheet tab color. 检索选项卡颜色时, 如果工作表不可见, 则值将为 null。When retrieving the tab color, if the worksheet is invisible, the value will be null. 如果工作表可见但选项卡颜色设置为自动, 将返回一个空字符串。If the worksheet is visible but the tab color is set to auto, an empty string will be returned. 否则, 在设置颜色时, 属性将设置为颜色, 格式为#"123456", 则使用空字符串设置 "自动" 颜色, 或使用实际颜色。Otherwise, the property will be set to a color, in the form "#123456" When setting the color, use an empty-string to set an "auto" color, or a real color otherwise.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

tables

属于工作表的表的集合。Collection of tables that are part of the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

verticalPageBreaks

获取工作表的垂直分页符集合。Gets the vertical page break collection for the worksheet. 此集合仅包含手动分页符。This collection only contains manual page breaks.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

visibility

工作表的可见性。The Visibility of the worksheet.

[API 集: ExcelApi 1.1 用于读取可见性; 1.2 用于设置。[ API set: ExcelApi 1.1 for reading visibility; 1.2 for setting it. ]

方法

activate()

在 Excel UI 中激活工作表。Activate the worksheet in the Excel UI.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

calculate(markAllDirty)

计算工作表上的所有单元格。Calculates all cells on a worksheet.

[API 集: ExcelApi 1.6][ API set: ExcelApi 1.6 ]

copy(positionType, relativeTo)

复制工作表并将其置于指定位置。Copy a worksheet and place it at the specified position. 返回复制的工作表。Return the copied worksheet.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

copy(positionTypeString, relativeTo)

复制工作表并将其置于指定位置。Copy a worksheet and place it at the specified position. 返回复制的工作表。Return the copied worksheet.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

delete()

从工作簿中删除工作表。Deletes the worksheet from the workbook. 请注意, 如果工作表的可见性设置为 "VeryHidden", 则删除操作将失败, 并出现 GeneralException。Note that if the worksheet's visibility is set to "VeryHidden", the delete operation will fail with a GeneralException.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

findAll(text, criteria)

根据指定的条件查找给定字符串的所有匹配项,并将它们作为包含一个或多个矩形区域的 RangeAreas 对象返回。Finds all occurrences of the given string based on the criteria specified and returns them as a RangeAreas object, comprising one or more rectangular ranges.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

findAllOrNullObject(text, criteria)

根据指定的条件查找给定字符串的所有匹配项,并将它们作为包含一个或多个矩形区域的 RangeAreas 对象返回。Finds all occurrences of the given string based on the criteria specified and returns them as a RangeAreas object, comprising one or more rectangular ranges.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getCell(row, column)

根据行和列编号获取包含单个单元格的 range 对象。Gets the range object containing the single cell based on row and column numbers. 单元格可以位于其父区域的边界之外, 但前提是它停留在工作表网格中。The cell can be outside the bounds of its parent range, so long as it stays within the worksheet grid.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

getNext(visibleOnly)

获取此工作表的后面的工作表。Gets the worksheet that follows this one. 如果此方法后面没有任何工作表, 则此方法将引发错误。If there are no worksheets following this one, this method will throw an error.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

getNextOrNullObject(visibleOnly)

获取此工作表的后面的工作表。Gets the worksheet that follows this one. 如果此方法后面没有任何工作表, 则此方法将返回一个 null 对象。If there are no worksheets following this one, this method will return a null object.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

getPrevious(visibleOnly)

获取此项之前的工作表。Gets the worksheet that precedes this one. 如果没有以前的工作表, 此方法将引发错误。If there are no previous worksheets, this method will throw an error.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

getPreviousOrNullObject(visibleOnly)

获取此项之前的工作表。Gets the worksheet that precedes this one. 如果没有以前的工作表, 则此方法将返回一个空的 objet。If there are no previous worksheets, this method will return a null objet.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

getRange(address)

获取一个 range 对象, 该对象代表由地址或名称指定的单个矩形单元格块。Gets the range object, representing a single rectangular block of cells, specified by the address or name.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

getRangeByIndexes(startRow, startColumn, rowCount, columnCount)

获取以特定行索引和列索引开始并跨越了一定数量的行和列的 range 对象。Gets the range object beginning at a particular row index and column index, and spanning a certain number of rows and columns.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

getRanges(address)

获取按地址或名称指定的 RangeAreas 对象,它表示一个或多个矩形区域块。Gets the RangeAreas object, representing one or more blocks of rectangular ranges, specified by the address or name.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getUsedRange(valuesOnly)

使用的区域是包含分配了值或格式化的任何单元格的最小区域。The used range is the smallest range that encompasses any cells that have a value or formatting assigned to them. 如果整个工作表为空, 则此函数将返回左上角单元格 (即, 它会引发错误)。If the entire worksheet is blank, this function will return the top left cell (i.e. it will not throw an error).

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

getUsedRangeOrNullObject(valuesOnly)

使用的区域是包含分配了值或格式的任意单元格的最小区域。如果整个工作表为空,此函数将返回 NULL 对象。The used range is the smallest range that encompasses any cells that have a value or formatting assigned to them. If the entire worksheet is blank, this function will return a null object.

[API 集: ExcelApi 1.4][ API set: ExcelApi 1.4 ]

load(option)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性之前,你必须调用“context.sync()”。You must call "context.sync()" before reading the properties.

load(propertyNames)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

replaceAll(text, replacement, criteria)

根据当前工作表中指定的条件查找并替换给定的字符串。Finds and replaces the given string based on the criteria specified within the current worksheet.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

set(properties, options)

同时设置一个对象的多个属性。Sets multiple properties of an object at the same time. 您可以传递具有相应属性的纯对象或相同类型的其他 API 对象。You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

基于现有加载的对象同时设置该对象的多个属性。Sets multiple properties on the object at the same time, based on an existing loaded object.

toJSON()

重写 JavaScript toJSON()方法, 以便在将 API 对象传递到时提供更有用的输出JSON.stringify()Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify反过来, 也会调用传递toJSON给它的对象的方法。尽管原始的 Excel 工作表对象是 API 对象, 但toJSON方法返回一个简单的 JavaScript 对象 (类型为Excel.Interfaces.WorksheetData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Worksheet object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.WorksheetData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

事件

onActivated

当激活工作表时发生此事件。Occurs when the worksheet is activated.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

onCalculated

在计算工作表时发生。Occurs when the worksheet is calculated.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

onChanged

当指定的工作表上的数据发生更改时发生。Occurs when data changed on a specific worksheet.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

onColumnSorted

在列上排序时发生。Occurs when sorting on columns.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

onDeactivated

停用工作表时发生此事件。Occurs when the worksheet is deactivated.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

onFiltered

在特定工作表上应用筛选器时发生。Occurs when filter is applied on a specific worksheet.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

onFormatChanged

在特定工作表上更改格式时发生。Occurs when format changed on a specific worksheet.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

onRowSorted

在行上排序时发生。Occurs when sorting on rows.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

onSelectionChanged

当指定的工作表上的所选内容更改时发生。Occurs when the selection changes on a specific worksheet.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

onSingleClicked

在工作表中进行左键单击/点击操作时发生。Occurs when left-clicked/tapped operation happens in the worksheet.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

属性详细信息

autoFilter

表示工作表的 AutoFilter 对象。Represents the AutoFilter object of the worksheet. 只读。Read-Only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly autoFilter: Excel.AutoFilter;

属性值

示例Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();
    const farmData = sheet.getUsedRange();

    // This filter will only show the rows with the top 25% of values in column 3.
    sheet.autoFilter.apply(farmData, 3, { criterion1: "25", filterOn: Excel.FilterOn.topPercent });
    await context.sync();
});

charts

返回属于工作表的图表的集合。Returns collection of charts that are part of the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly charts: Excel.ChartCollection;

属性值

comments

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

返回工作表上的所有 Comments 对象的集合。Returns a collection of all the Comments objects on the worksheet. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly comments: Excel.CommentCollection;

属性值

context

与该对象关联的请求上下文。The request context associated with the object. 这会将加载项的进程连接到 Office 主机应用程序的进程。This connects the add-in's process to the Office host application's process.

context: RequestContext;

属性值

RequestContext

enableCalculation

获取或设置工作表的 enableCalculation 属性。Gets or sets the enableCalculation property of the worksheet. 如此如果 Excel 根据需要重新计算工作表。True if Excel recalculates the worksheet when necessary. 如果 Excel 不重新计算工作表,则该值为 False。False if Excel doesn't recalculate the sheet.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

enableCalculation: boolean;

属性值

boolean

freezePanes

获取一个对象, 该对象可用于操作工作表上的冻结窗格。Gets an object that can be used to manipulate frozen panes on the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly freezePanes: Excel.WorksheetFreezePanes;

属性值

horizontalPageBreaks

获取工作表的水平分页符集合。Gets the horizontal page break collection for the worksheet. 此集合仅包含手动分页符。This collection only contains manual page breaks.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly horizontalPageBreaks: Excel.PageBreakCollection;

属性值

id

返回用于唯一标识指定工作簿中工作表的值。即使工作表被重命名或移动,标识符的值仍然相同。只读。Returns a value that uniquely identifies the worksheet in a given workbook. The value of the identifier remains the same even when the worksheet is renamed or moved. Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly id: string;

属性值

string

name

工作表的显示名称。The display name of the worksheet.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

name: string;

属性值

string

names

一组范围限定到当前工作表的名称。Collection of names scoped to the current worksheet. 只读。Read-only.

[API 集: ExcelApi 1.4][ API set: ExcelApi 1.4 ]

readonly names: Excel.NamedItemCollection;

属性值

pageLayout

获取工作表的 PageLayout 对象。Gets the PageLayout object of the worksheet.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly pageLayout: Excel.PageLayout;

属性值

pivotTables

一组属于 worksheet 的 PivotTable 对象。Collection of PivotTables that are part of the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

readonly pivotTables: Excel.PivotTableCollection;

属性值

position

工作表在工作簿中的位置,从零开始。The zero-based position of the worksheet within the workbook.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

position: number;

属性值

number

protection

返回表工作表的工作表保护对象。Returns sheet protection object for a worksheet. 只读。Read-only.

[API 集: ExcelApi 1.2][ API set: ExcelApi 1.2 ]

readonly protection: Excel.WorksheetProtection;

属性值

shapes

返回工作表上的所有 Shape 对象的集合。Returns the collection of all the Shape objects on the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly shapes: Excel.ShapeCollection;

属性值

showGridlines

获取或设置工作表的网格线标志。Gets or sets the worksheet's gridlines flag. 此标志确定是否对用户显示网格线。This flag determines whether gridlines are visible to the user.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

showGridlines: boolean;

属性值

boolean

示例Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.showGridlines = true;

    await context.sync();
});

showHeadings

获取或设置工作表的标题标志。Gets or sets the worksheet's headings flag. 此标志确定是否对用户显示标题。This flag determines whether headings are visible to the user.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

showHeadings: boolean;

属性值

boolean

slicers

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

返回作为工作表一部分的切片器集合。Returns collection of slicers that are part of the worksheet. 只读。Read-only.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly slicers: Excel.SlicerCollection;

属性值

示例Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Pivot");
    const slicer = sheet.slicers.add(
        "Farm Sales", /* The slicer data source. For PivotTables, this can be the PivotTable object reference or name. */
        "Type" /* The field in the data source to filter by. For PivotTables, this can be a PivotField object reference or ID. */
    );
    slicer.name = "Fruit Slicer";
    await context.sync();
});

standardHeight

返回工作表中所有行的标准(默认)行高,以磅为单位。Returns the standard (default) height of all the rows in the worksheet, in points. 只读。Read-only.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly standardHeight: number;

属性值

number

standardWidth

返回或设置工作表中所有列的标准(默认)列宽。Returns or sets the standard (default) width of all the columns in the worksheet. 一个列宽单位等于“常规”样式中一个字符的宽度。One unit of column width is equal to the width of one character in the Normal style. 对于比例字体,则使用字符 0(零)的宽度。For proportional fonts, the width of the character 0 (zero) is used.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

standardWidth: number;

属性值

number

tabColor

获取或设置工作表标签颜色。Gets or sets the worksheet tab color. 检索选项卡颜色时, 如果工作表不可见, 则值将为 null。When retrieving the tab color, if the worksheet is invisible, the value will be null. 如果工作表可见但选项卡颜色设置为自动, 将返回一个空字符串。If the worksheet is visible but the tab color is set to auto, an empty string will be returned. 否则, 在设置颜色时, 属性将设置为颜色, 格式为#"123456", 则使用空字符串设置 "自动" 颜色, 或使用实际颜色。Otherwise, the property will be set to a color, in the form "#123456" When setting the color, use an empty-string to set an "auto" color, or a real color otherwise.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

tabColor: string;

属性值

string

示例Examples

await Excel.run(async (context) => {
    const activeSheet = context.workbook.worksheets.getActiveWorksheet();
    activeSheet.tabColor = "#FF0000";

    await context.sync();
});

tables

属于工作表的表的集合。Collection of tables that are part of the worksheet. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly tables: Excel.TableCollection;

属性值

verticalPageBreaks

获取工作表的垂直分页符集合。Gets the vertical page break collection for the worksheet. 此集合仅包含手动分页符。This collection only contains manual page breaks.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly verticalPageBreaks: Excel.PageBreakCollection;

属性值

visibility

工作表的可见性。The Visibility of the worksheet.

[API 集: ExcelApi 1.1 用于读取可见性; 1.2 用于设置。[ API set: ExcelApi 1.1 for reading visibility; 1.2 for setting it. ]

visibility: Excel.SheetVisibility | "Visible" | "Hidden" | "VeryHidden";

属性值

Excel.SheetVisibility | "Visible" | "Hidden" | "VeryHidden"

方法详细信息

activate()

在 Excel UI 中激活工作表。Activate the worksheet in the Excel UI.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

activate(): void;

返回

void

示例Examples

Excel.run(function (ctx) { 
    var wSheetName = 'Sheet1';
    var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
    worksheet.activate();
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

calculate(markAllDirty)

计算工作表上的所有单元格。Calculates all cells on a worksheet.

[API 集: ExcelApi 1.6][ API set: ExcelApi 1.6 ]

calculate(markAllDirty: boolean): void;

参数

markAllDirty
boolean

如果为 True, 则将全部标记为已更新。True, to mark all as dirty.

返回

void

copy(positionType, relativeTo)

复制工作表并将其置于指定位置。Copy a worksheet and place it at the specified position. 返回复制的工作表。Return the copied worksheet.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

copy(positionType?: Excel.WorksheetPositionType, relativeTo?: Excel.Worksheet): Excel.Worksheet;

参数

positionType
Excel.WorksheetPositionType

可选。Optional.

relativeTo
Excel.Worksheet

可选。Optional.

返回

示例Examples

await Excel.run(async (context) => {

    let myWorkbook = context.workbook;
    let sampleSheet = myWorkbook.worksheets.getActiveWorksheet();
    let copiedSheet = sampleSheet.copy("End")

    sampleSheet.load("name");
    copiedSheet.load("name");

    await context.sync();

    console.log("'" + sampleSheet.name + "' was copied to '" + copiedSheet.name + "'")
});

copy(positionTypeString, relativeTo)

复制工作表并将其置于指定位置。Copy a worksheet and place it at the specified position. 返回复制的工作表。Return the copied worksheet.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

copy(positionTypeString?: "None" | "Before" | "After" | "Beginning" | "End", relativeTo?: Excel.Worksheet): Excel.Worksheet;

参数

positionTypeString
"None" | "Before" | "After" | "Beginning" | "End"

可选。Optional.

relativeTo
Excel.Worksheet

可选。Optional.

返回

delete()

从工作簿中删除工作表。Deletes the worksheet from the workbook. 请注意, 如果工作表的可见性设置为 "VeryHidden", 则删除操作将失败, 并出现 GeneralException。Note that if the worksheet's visibility is set to "VeryHidden", the delete operation will fail with a GeneralException.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

delete(): void;

返回

void

示例Examples

Excel.run(function (ctx) { 
    var wSheetName = 'Sheet1';
    var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
    worksheet.delete();
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

findAll(text, criteria)

根据指定的条件查找给定字符串的所有匹配项,并将它们作为包含一个或多个矩形区域的 RangeAreas 对象返回。Finds all occurrences of the given string based on the criteria specified and returns them as a RangeAreas object, comprising one or more rectangular ranges.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

findAll(text: string, criteria: Excel.WorksheetSearchCriteria): Excel.RangeAreas;

参数

text
string

要查找的字符串。The string to find.

criteria
Excel.WorksheetSearchCriteria

其他搜索条件, 包括搜索是否需要匹配整个单元格或是否区分大小写。Additional search criteria, including whether the search needs to match the entire cell or be case sensitive.

返回

一个 RangeArea 对象, 其中包含一个或多个与搜索条件相匹配的矩形区域。A RangeArea object, comprising one or more rectangular ranges, that matches the search criteria. 如果没有满足此条件的单元格, 则将引发 ItemNotFound 错误。If no cells meet this criteria, an ItemNotFound error will be thrown.

findAllOrNullObject(text, criteria)

根据指定的条件查找给定字符串的所有匹配项,并将它们作为包含一个或多个矩形区域的 RangeAreas 对象返回。Finds all occurrences of the given string based on the criteria specified and returns them as a RangeAreas object, comprising one or more rectangular ranges.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

findAllOrNullObject(text: string, criteria: Excel.WorksheetSearchCriteria): Excel.RangeAreas;

参数

text
string

要查找的字符串。The string to find.

criteria
Excel.WorksheetSearchCriteria

其他搜索条件, 包括搜索是否需要匹配整个单元格或是否区分大小写。Additional search criteria, including whether the search needs to match the entire cell or be case sensitive.

返回

一个 RangeArea 对象, 其中包含一个或多个与搜索条件相匹配的矩形区域。A RangeArea object, comprising one or more rectangular ranges, that matches the search criteria. 如果没有匹配项, 则此函数将返回一个 null 对象。If there are no matches, this function will return a null object.

示例Examples

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");
    const foundRanges = sheet.findAllOrNullObject("Complete", {
        completeMatch: true,
        matchCase: false
    });

    await context.sync();

    if (foundRanges.isNullObject) {
        console.log("No complete projects");
    } else {
        foundRanges.format.fill.color = "green"
    }
});

getCell(row, column)

根据行和列编号获取包含单个单元格的 range 对象。Gets the range object containing the single cell based on row and column numbers. 单元格可以位于其父区域的边界之外, 但前提是它停留在工作表网格中。The cell can be outside the bounds of its parent range, so long as it stays within the worksheet grid.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

getCell(row: number, column: number): Excel.Range;

参数

row
number

要检索的单元格的行号。The row number of the cell to be retrieved. 从零开始编制索引。Zero-indexed.

column
number

要检索的单元格的列号。the column number of the cell to be retrieved. 从零开始编制索引。Zero-indexed.

返回

示例Examples

Excel.run(function (ctx) { 
    var sheetName = "Sheet1";
    var rangeAddress = "A1:F8";
    var worksheet = ctx.workbook.worksheets.getItem(sheetName);
    var cell = worksheet.getCell(0,0);
    cell.load('address');
    return ctx.sync().then(function() {
        console.log(cell.address);
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getNext(visibleOnly)

获取此工作表的后面的工作表。Gets the worksheet that follows this one. 如果此方法后面没有任何工作表, 则此方法将引发错误。If there are no worksheets following this one, this method will throw an error.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

getNext(visibleOnly?: boolean): Excel.Worksheet;

参数

visibleOnly
boolean

可选。Optional. 如果为 true, 则只考虑可见的工作表, 跳过任何隐藏的工作表。If true, considers only visible worksheets, skipping over any hidden ones.

返回

示例Examples

await Excel.run(async (context) => {
    const sheets = context.workbook.worksheets;

    // We don't want to include the default worksheet that was created
    // when the workbook was created, so our "firstSheet" will be the one
    // after the literal first. Note chaining of navigation methods.
    const firstSheet = sheets.getFirst().getNext();
    const lastSheet = sheets.getLast();
    const firstTaxRateRange = firstSheet.getRange("B2");
    const lastTaxRateRange = lastSheet.getRange("B2");

    firstSheet.load("name");
    lastSheet.load("name");
    firstTaxRateRange.load("text");
    lastTaxRateRange.load("text");

    await context.sync();

    let firstYear = firstSheet.name.substr(5, 4);
    let lastYear = lastSheet.name.substr(5, 4);
    console.log(`Tax Rate change from ${firstYear} to ${lastYear}`, `Tax rate for ${firstYear}: ${firstTaxRateRange.text[0][0]}\nTax rate for ${lastYear}: ${lastTaxRateRange.text[0][0]}`)

    await context.sync();
});

getNextOrNullObject(visibleOnly)

获取此工作表的后面的工作表。Gets the worksheet that follows this one. 如果此方法后面没有任何工作表, 则此方法将返回一个 null 对象。If there are no worksheets following this one, this method will return a null object.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

getNextOrNullObject(visibleOnly?: boolean): Excel.Worksheet;

参数

visibleOnly
boolean

可选。Optional. 如果为 true, 则只考虑可见的工作表, 跳过任何隐藏的工作表。If true, considers only visible worksheets, skipping over any hidden ones.

返回

getPrevious(visibleOnly)

获取此项之前的工作表。Gets the worksheet that precedes this one. 如果没有以前的工作表, 此方法将引发错误。If there are no previous worksheets, this method will throw an error.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

getPrevious(visibleOnly?: boolean): Excel.Worksheet;

参数

visibleOnly
boolean

可选。Optional. 如果为 true, 则只考虑可见的工作表, 跳过任何隐藏的工作表。If true, considers only visible worksheets, skipping over any hidden ones.

返回

示例Examples

await Excel.run(async (context) => {
    const sheets = context.workbook.worksheets;
    const currentSheet = sheets.getActiveWorksheet();
    const previousYearSheet = currentSheet.getPrevious();
    const currentTaxDueRange = currentSheet.getRange("C2");
    const previousTaxDueRange = previousYearSheet.getRange("C2");

    currentSheet.load("name");
    previousYearSheet.load("name");
    currentTaxDueRange.load("text");
    previousTaxDueRange.load("text");

    await context.sync();

    let currentYear = currentSheet.name.substr(5, 4);
    let previousYear = previousYearSheet.name.substr(5, 4);
    console.log("Two Year Tax Due Comparison", `Tax due for ${currentYear} was ${currentTaxDueRange.text[0][0]}\nTax due for ${previousYear} was ${previousTaxDueRange.text[0][0]}`)

    await context.sync();
});

getPreviousOrNullObject(visibleOnly)

获取此项之前的工作表。Gets the worksheet that precedes this one. 如果没有以前的工作表, 则此方法将返回一个空的 objet。If there are no previous worksheets, this method will return a null objet.

[API 集: ExcelApi 1.5][ API set: ExcelApi 1.5 ]

getPreviousOrNullObject(visibleOnly?: boolean): Excel.Worksheet;

参数

visibleOnly
boolean

可选。Optional. 如果为 true, 则只考虑可见的工作表, 跳过任何隐藏的工作表。If true, considers only visible worksheets, skipping over any hidden ones.

返回

getRange(address)

获取一个 range 对象, 该对象代表由地址或名称指定的单个矩形单元格块。Gets the range object, representing a single rectangular block of cells, specified by the address or name.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

getRange(address?: string): Excel.Range;

参数

address
string

可选。Optional. 表示地址或范围名称的字符串。The string representing the address or name of the range. 例如, "A1: B2"。For example, "A1:B2". 如果未指定,则返回整个工作表区域。If not specified, the entire worksheet range is returned.

返回

示例Examples

// Below example uses range address to get the range object.
Excel.run(function (ctx) { 
    var sheetName = "Sheet1";
    var rangeAddress = "A1:F8";
    var worksheet = ctx.workbook.worksheets.getItem(sheetName);
    var range = worksheet.getRange(rangeAddress);
    range.load('cellCount');
    return ctx.sync().then(function() {
        console.log(range.cellCount);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
// Below example uses a named-range to get the range object.
Excel.run(function (ctx) { 
    var sheetName = "Sheet1";
    var rangeName = 'MyRange';
    var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeName);
    range.load('address');
    return ctx.sync().then(function() {
        console.log(range.address);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getRangeByIndexes(startRow, startColumn, rowCount, columnCount)

获取以特定行索引和列索引开始并跨越了一定数量的行和列的 range 对象。Gets the range object beginning at a particular row index and column index, and spanning a certain number of rows and columns.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

getRangeByIndexes(startRow: number, startColumn: number, rowCount: number, columnCount: number): Excel.Range;

参数

startRow
number

起始行 (零编制索引)。Start row (zero-indexed).

startColumn
number

Start 列 (零个索引)。Start column (zero-indexed).

rowCount
number

要包含在范围中的行数。Number of rows to include in the range.

columnCount
number

要包含在范围中的列数。Number of columns to include in the range.

返回

getRanges(address)

获取按地址或名称指定的 RangeAreas 对象,它表示一个或多个矩形区域块。Gets the RangeAreas object, representing one or more blocks of rectangular ranges, specified by the address or name.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getRanges(address?: string): Excel.RangeAreas;

参数

address
string

可选。Optional. 一个包含以逗号分隔的地址或各个区域的名称的字符串。A string containing the comma-separated addresses or names of the individual ranges. 例如, "A1: B2, A5: B5"。For example, "A1:B2, A5:B5". 如果未指定, 则返回整个工作表的 RangeArea 对象。If not specified, an RangeArea object for the entire worksheet is returned.

返回

示例Examples

await Excel.run(async (context) => {

    const sheet = context.workbook.worksheets.getActiveWorksheet();
    const specifiedRanges = sheet.getRanges("D3:D5, G3:G5");
    specifiedRanges.format.fill.color = "pink";

    await context.sync();
})

getUsedRange(valuesOnly)

使用的区域是包含分配了值或格式化的任何单元格的最小区域。The used range is the smallest range that encompasses any cells that have a value or formatting assigned to them. 如果整个工作表为空, 则此函数将返回左上角单元格 (即, 它会引发错误)。If the entire worksheet is blank, this function will return the top left cell (i.e. it will not throw an error).

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

getUsedRange(valuesOnly?: boolean): Excel.Range;

参数

valuesOnly
boolean

可选。Optional. 如果为 true, 则仅考虑值为已使用单元格的单元格 (忽略格式设置)。If true, considers only cells with values as used cells (ignoring formatting). [Api 集: ExcelApi 1。2][Api set: ExcelApi 1.2]

返回

示例Examples

Excel.run(function (ctx) { 
    var wSheetName = 'Sheet1';
    var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
    var usedRange = worksheet.getUsedRange();
    usedRange.load('address');
    return ctx.sync().then(function() {
            console.log(usedRange.address);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getUsedRangeOrNullObject(valuesOnly)

使用的区域是包含分配了值或格式的任意单元格的最小区域。如果整个工作表为空,此函数将返回 NULL 对象。The used range is the smallest range that encompasses any cells that have a value or formatting assigned to them. If the entire worksheet is blank, this function will return a null object.

[API 集: ExcelApi 1.4][ API set: ExcelApi 1.4 ]

getUsedRangeOrNullObject(valuesOnly?: boolean): Excel.Range;

参数

valuesOnly
boolean

可选。Optional. 仅将有值的单元格视为已使用的单元格。Considers only cells with values as used cells.

返回

load(option)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性之前,你必须调用“context.sync()”。You must call "context.sync()" before reading the properties.

load(option?: Excel.Interfaces.WorksheetLoadOptions): Excel.Worksheet;

参数

返回

注解

除了此签名之外, 此方法还具有以下签名:In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.Worksheet-Where 选项是一个逗号分隔的字符串或一个字符串数组, 用于指定要加载的属性。load(option?: string | string[]): Excel.Worksheet - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Excel.Worksheet-Where 选项。选择是一个用逗号分隔的字符串, 用于指定要加载的属性和选项。 expand 是一个用逗号分隔的字符串, 用于指定要加载的导航属性。load(option?: { select?: string; expand?: string; }): Excel.Worksheet - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.Worksheet-仅适用于集合类型。load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.Worksheet - Only available on collection types. 它类似于前面的签名。It is similar to the preceding signature. Top 指定结果中可包含的集合项的最大数量。Option.top specifies the maximum number of collection items that can be included in the result. 选项。 skip 指定要跳过且不包含在结果中的项目数。Option.skip specifies the number of items that are to be skipped and not included in the result. 如果指定了 top 选项, 则在跳过指定数目的项目后将启动结果集。If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.Worksheet;

参数

propertyNames
string | string[]

一个以逗号分隔的字符串或字符串数组, 用于指定要加载的属性。A comma-delimited string or an array of strings that specify the properties to load.

返回

示例Examples

// Get worksheet properties based on sheet name.
Excel.run(function (ctx) { 
    var wSheetName = 'Sheet1';
    var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
    worksheet.load('position')
    return ctx.sync().then(function() {
            console.log(worksheet.position);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
// Set worksheet position. 
Excel.run(function (ctx) { 
    var wSheetName = 'Sheet1';
    var worksheet = ctx.workbook.worksheets.getItem(wSheetName);
    worksheet.position = 2;
    return ctx.sync(); 
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: { select?: string; expand?: string; }): Excel.Worksheet;

参数

propertyNamesAndPaths
{ select?: string; expand?: string; }

其中, propertyNamesAndPaths 是用逗号分隔的字符串, 用于指定要加载的属性和 propertyNamesAndPaths。扩展是一个用逗号分隔的字符串, 用于指定要加载的导航属性。Where propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

返回

replaceAll(text, replacement, criteria)

根据当前工作表中指定的条件查找并替换给定的字符串。Finds and replaces the given string based on the criteria specified within the current worksheet.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

replaceAll(text: string, replacement: string, criteria: Excel.ReplaceCriteria): OfficeExtension.ClientResult<number>;

参数

text
string

要查找的字符串。String to find.

replacement
string

要将原始替换为的字符串。String to replace the original with.

criteria
Excel.ReplaceCriteria

其他替换条件。Additional Replace Criteria.

返回

OfficeExtension.ClientResult<number>

执行的替换的次数。The number of replacements performed.

set(properties, options)

同时设置一个对象的多个属性。Sets multiple properties of an object at the same time. 您可以传递具有相应属性的纯对象或相同类型的其他 API 对象。You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties: Interfaces.WorksheetUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
Interfaces.WorksheetUpdateData

一个 JavaScript 对象, 其属性的结构 isomorphically 为在其上调用方法的对象的属性。A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

提供一个选项, 以在 properties 对象尝试设置任何只读属性时禁止显示错误。Provides an option to suppress errors if the properties object tries to set any read-only properties.

返回

void

注解

此方法具有以下附加签名:This method has the following additional signature:

set(properties: Excel.Worksheet): void

set(properties)

基于现有加载的对象同时设置该对象的多个属性。Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.Worksheet): void;

参数

properties
Excel.Worksheet

返回

void

toJSON()

重写 JavaScript toJSON()方法, 以便在将 API 对象传递到时提供更有用的输出JSON.stringify()Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify反过来, 也会调用传递toJSON给它的对象的方法。尽管原始的 Excel 工作表对象是 API 对象, 但toJSON方法返回一个简单的 JavaScript 对象 (类型为Excel.Interfaces.WorksheetData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.Worksheet object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.WorksheetData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.WorksheetData;

返回

事件详细信息

onActivated

当激活工作表时发生此事件。Occurs when the worksheet is activated.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly onActivated: OfficeExtension.EventHandlers<Excel.WorksheetActivatedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetActivatedEventArgs>

示例Examples

Excel.run(function (context) {
    var sheet = context.workbook.worksheets.getItem("Sample");
    sheet.onActivated.add(function (event) {
        return Excel.run((context) => {
            console.log("The activated worksheet ID is: " + event.worksheetId);
            return context.sync();
        });
    });
    return context.sync();
});

onCalculated

在计算工作表时发生。Occurs when the worksheet is calculated.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

readonly onCalculated: OfficeExtension.EventHandlers<Excel.WorksheetCalculatedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetCalculatedEventArgs>

示例Examples

Excel.run(function (context) {
    var sheet = context.workbook.worksheets.getItem("Sample");
    sheet.onCalculated.add(function (event) {
        return Excel.run((context) => {
            console.log("The worksheet has recalculated.");
            return context.sync();
        });
    });
    return context.sync();
});

onChanged

当指定的工作表上的数据发生更改时发生。Occurs when data changed on a specific worksheet.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly onChanged: OfficeExtension.EventHandlers<Excel.WorksheetChangedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetChangedEventArgs>

示例Examples

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.onChanged.add(onChange);

    await context.sync();
    console.log("A handler has been registered for the onChanged event.");
});

onColumnSorted

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

在列上排序时发生。Occurs when sorting on columns.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly onColumnSorted: OfficeExtension.EventHandlers<Excel.WorksheetColumnSortedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetColumnSortedEventArgs>

onDeactivated

停用工作表时发生此事件。Occurs when the worksheet is deactivated.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly onDeactivated: OfficeExtension.EventHandlers<Excel.WorksheetDeactivatedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetDeactivatedEventArgs>

示例Examples

Excel.run(function (context) {
    var sheet = context.workbook.worksheets.getItem("Sample");
    sheet.onDeactivated.add(function (event) {
        return Excel.run((context) => {
            console.log("The deactivated worksheet is: " + event.worksheetId);
            return context.sync();
        });
    });
    return context.sync();
});

onFiltered

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

在特定工作表上应用筛选器时发生。Occurs when filter is applied on a specific worksheet.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly onFiltered: OfficeExtension.EventHandlers<Excel.WorksheetFilteredEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetFilteredEventArgs>

onFormatChanged

在特定工作表上更改格式时发生。Occurs when format changed on a specific worksheet.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

readonly onFormatChanged: OfficeExtension.EventHandlers<Excel.WorksheetFormatChangedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetFormatChangedEventArgs>

onRowSorted

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

在行上排序时发生。Occurs when sorting on rows.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly onRowSorted: OfficeExtension.EventHandlers<Excel.WorksheetRowSortedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetRowSortedEventArgs>

onSelectionChanged

当指定的工作表上的所选内容更改时发生。Occurs when the selection changes on a specific worksheet.

[API 集: ExcelApi 1.7][ API set: ExcelApi 1.7 ]

readonly onSelectionChanged: OfficeExtension.EventHandlers<Excel.WorksheetSelectionChangedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetSelectionChangedEventArgs>

示例Examples

Excel.run(function (context) {
    var sheet = context.workbook.worksheets.getItem("Sample");
    sheet.onSelectionChanged.add(function (event) {
        return Excel.run((context) => {
            console.log("The selected range has changed to: " + event.address);
            return context.sync();
        });
    });
    return context.sync();
});

onSingleClicked

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

在工作表中进行左键单击/点击操作时发生。Occurs when left-clicked/tapped operation happens in the worksheet.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

readonly onSingleClicked: OfficeExtension.EventHandlers<Excel.WorksheetSingleClickedEventArgs>;

返回

OfficeExtension.EventHandlers<Excel.WorksheetSingleClickedEventArgs>