Excel.Query class

表示 Power Query 查询。

扩展

属性

context

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

error

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

loadedTo

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

loadedToDataModel

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

name

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

refreshDate

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

rowsLoadedCount

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

方法

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

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

方法详细信息

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 指定要加载的导航属性的逗号分隔字符串。

返回

toJSON()

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

toJSON(): Excel.Interfaces.QueryData;

返回