Excel.Query class

表示Power Query查询。

Extends

注解

[ API 集:ExcelApi 1.14 ]

属性

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

error

从上次刷新查询时获取查询错误消息。

loadedTo

获取加载到对象类型的查询。

loadedToDataModel

指定是否将查询加载到数据模型。

name

获取查询的名称。 查询名称不能包含句点或引号。

refreshDate

获取上次刷新查询的日期和时间。

rowsLoadedCount

获取上次刷新查询时加载的行数。 如果上次刷新时出现错误,则值为 -1。

方法

delete()

删除查询和关联的连接。 与查询关联的表将不再连接。

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

refresh()

刷新查询。 这只会启动刷新。

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 虽然原始 Excel.Query 对象是 API 对象,但toJSON该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.QueryData) ,该对象包含从原始对象加载的任何子属性的浅表副本。

属性详细信息

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

error

从上次刷新查询时获取查询错误消息。

readonly error: Excel.QueryError | "Unknown" | "None" | "FailedLoadToWorksheet" | "FailedLoadToDataModel" | "FailedDownload" | "FailedToCompleteDownload";

属性值

Excel.QueryError | "Unknown" | "None" | "FailedLoadToWorksheet" | "FailedLoadToDataModel" | "FailedDownload" | "FailedToCompleteDownload"

注解

[ API 集:ExcelApi 1.14 ]

loadedTo

获取加载到对象类型的查询。

readonly loadedTo: Excel.LoadToType | "ConnectionOnly" | "Table" | "PivotTable" | "PivotChart";

属性值

Excel.LoadToType | "ConnectionOnly" | "Table" | "PivotTable" | "PivotChart"

注解

[ API 集:ExcelApi 1.14 ]

loadedToDataModel

指定是否将查询加载到数据模型。

readonly loadedToDataModel: boolean;

属性值

boolean

注解

[ API 集:ExcelApi 1.14 ]

name

获取查询的名称。 查询名称不能包含句点或引号。

readonly name: string;

属性值

string

注解

[ API 集:ExcelApi 1.14 ]

示例

// This function retrieves the query collection in a workbook, 
// loads the query items in that collection, and then
// logs the name of each query to the console.
await Excel.run(async (context) => {
    const queries = context.workbook.queries; 
    queries.load("items"); 
    await context.sync(); 

    console.log("Name of each query: ")
    console.log("  " + queries.items.map((query) => query.name).join("\n  "));
});

refreshDate

获取上次刷新查询的日期和时间。

readonly refreshDate: Date;

属性值

Date

注解

[ API 集:ExcelApi 1.14 ]

示例

// This function retrieves the query collection in a workbook, 
// loads the query items in that collection, and then
// logs the last refresh date of each query to the console.
await Excel.run(async (context) => {
    const queries = context.workbook.queries; 
    queries.load("items"); 
    await context.sync(); 

    console.log("Last refresh date of each query: ")
    console.log("  " + queries.items.map((query) => query.refreshDate).join("\n  "));
});       

rowsLoadedCount

获取上次刷新查询时加载的行数。 如果上次刷新时出现错误,则值为 -1。

readonly rowsLoadedCount: number;

属性值

number

注解

[ API 集:ExcelApi 1.14 ]

示例

// This function retrieves the query collection in a workbook, 
// loads the query items in that collection, and then
// logs the number of rows loaded in each query.
await Excel.run(async (context) => {
    const queries = context.workbook.queries; 
    queries.load("items"); 
    await context.sync(); 

    console.log("Rows loaded from each query: ")
    console.log("  " + queries.items.map((query) => query.rowsLoadedCount).join("\n  "));
});

方法详细信息

delete()

注意

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

删除查询和关联的连接。 与查询关联的表将不再连接。

delete(): void;

返回

void

注解

[ API 集:ExcelApi BETA (仅预览版) ]

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: Excel.Interfaces.QueryLoadOptions): Excel.Query;

参数

options
Excel.Interfaces.QueryLoadOptions

提供要加载对象的属性的选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

propertyNames

string | string[]

逗号分隔的字符串或指定要加载的属性的字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

propertyNamesAndPaths

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

propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。

返回

refresh()

注意

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

刷新查询。 这只会启动刷新。

refresh(): void;

返回

void

注解

[ API 集:ExcelApi BETA (仅预览版) ]

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 虽然原始 Excel.Query 对象是 API 对象,但toJSON该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.QueryData) ,该对象包含从原始对象加载的任何子属性的浅表副本。

toJSON(): Excel.Interfaces.QueryData;

返回