Excel.PivotLayout class

表示数据透视表的视觉布局。

扩展

注解

[ API 集:ExcelApi 1.8 ]

属性

context

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

layoutType

此属性指示数据透视表上的所有字段的 PivotLayoutType。 如果字段状态不同,则为 null。

showColumnGrandTotals

指定数据透视表是否显示列的总计。

showRowGrandTotals

指定数据透视表是否显示行的总计。

subtotalLocation

此属性指示 SubtotalLocationType 数据透视表上所有字段的 。 如果字段具有不同的状态,则为 null

方法

getColumnLabelRange()

返回数据透视表列标签所在位置的区域。

getDataBodyRange()

返回数据透视表数据值所在位置的区域。

getFilterAxisRange()

返回数据透视表筛选区的区域。

getRange()

返回存在数据透视表的区域,不包括筛选区。

getRowLabelRange()

返回数据透视表行标签所在位置的区域。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。

set(properties)

基于现有的已加载对象,同时对对象设置多个属性。

toJSON()

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

属性详细信息

context

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

context: RequestContext;

属性值

layoutType

此属性指示数据透视表上的所有字段的 PivotLayoutType。 如果字段状态不同,则为 null。

layoutType: Excel.PivotLayoutType | "Compact" | "Tabular" | "Outline";

属性值

Excel.PivotLayoutType | "Compact" | "Tabular" | "Outline"

注解

[ API 集:ExcelApi 1.8 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-pivotlayout.yaml

await Excel.run(async (context) => {
  // Change the PivotLayout.type to a new type.
  const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");
  pivotTable.layout.load("layoutType");
  await context.sync();

  // Cycle between the three layout types.
  if (pivotTable.layout.layoutType === "Compact") {
    pivotTable.layout.layoutType = "Outline";
  } else if (pivotTable.layout.layoutType === "Outline") {
    pivotTable.layout.layoutType = "Tabular";
  } else {
    pivotTable.layout.layoutType = "Compact";
  }

  await context.sync();
  console.log("Pivot layout is now " + pivotTable.layout.layoutType);
});

showColumnGrandTotals

指定数据透视表是否显示列的总计。

showColumnGrandTotals: boolean;

属性值

boolean

注解

[ API 集:ExcelApi 1.8 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-pivotlayout.yaml

await Excel.run(async (context) => {
  // Turn the grand totals on and off for the rows and columns.
  const pivotTable = context.workbook.pivotTables.getItem("Farm Sales");
  const pivotLayout = pivotTable.layout;

  pivotLayout.load(["showRowGrandTotals", "showColumnGrandTotals"]);
  await context.sync();

  let showColumnTotals = !pivotLayout.showColumnGrandTotals;
  let showRowTotals = !pivotLayout.showRowGrandTotals;
  console.log(`Show column grand totals? - ${showColumnTotals}`);
  console.log(`Show row grand totals? - ${showRowTotals}`);

  pivotLayout.showColumnGrandTotals = showColumnTotals;
  pivotLayout.showRowGrandTotals = showRowTotals;

  await context.sync();
});

showRowGrandTotals

指定数据透视表是否显示行的总计。

showRowGrandTotals: boolean;

属性值

boolean

注解

[ API 集:ExcelApi 1.8 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-pivotlayout.yaml

await Excel.run(async (context) => {
  // Turn the grand totals on and off for the rows and columns.
  const pivotTable = context.workbook.pivotTables.getItem("Farm Sales");
  const pivotLayout = pivotTable.layout;

  pivotLayout.load(["showRowGrandTotals", "showColumnGrandTotals"]);
  await context.sync();

  let showColumnTotals = !pivotLayout.showColumnGrandTotals;
  let showRowTotals = !pivotLayout.showRowGrandTotals;
  console.log(`Show column grand totals? - ${showColumnTotals}`);
  console.log(`Show row grand totals? - ${showRowTotals}`);

  pivotLayout.showColumnGrandTotals = showColumnTotals;
  pivotLayout.showRowGrandTotals = showRowTotals;

  await context.sync();
});

subtotalLocation

此属性指示 SubtotalLocationType 数据透视表上所有字段的 。 如果字段具有不同的状态,则为 null

subtotalLocation: Excel.SubtotalLocationType | "AtTop" | "AtBottom" | "Off";

属性值

Excel.SubtotalLocationType | "AtTop" | "AtBottom" | "Off"

注解

[ API 集:ExcelApi 1.8 ]

方法详细信息

getColumnLabelRange()

返回数据透视表列标签所在位置的区域。

getColumnLabelRange(): Excel.Range;

返回

注解

[ API 集:ExcelApi 1.8 ]

getDataBodyRange()

返回数据透视表数据值所在位置的区域。

getDataBodyRange(): Excel.Range;

返回

注解

[ API 集:ExcelApi 1.8 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-filters-and-summaries.yaml

await Excel.run(async (context) => {
    const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");

    // The layout controls the ranges used by the PivotTable.
    const range = pivotTable.layout.getDataBodyRange();

    // Get all the data hierarchy totals.
    const grandTotalRange = range.getLastRow();
    grandTotalRange.load("address");
    await context.sync();
    
    // Use the wholesale and farm sale totals to make a final sum.
    const masterTotalRange = context.workbook.worksheets.getActiveWorksheet().getRange("B27:C27");
    masterTotalRange.formulas = [["All Crates", "=SUM(" + grandTotalRange.address + ")"]];
    await context.sync();
});

getFilterAxisRange()

返回数据透视表筛选区的区域。

getFilterAxisRange(): Excel.Range;

返回

注解

[ API 集:ExcelApi 1.8 ]

getRange()

返回存在数据透视表的区域,不包括筛选区。

getRange(): Excel.Range;

返回

注解

[ API 集:ExcelApi 1.8 ]

getRowLabelRange()

返回数据透视表行标签所在位置的区域。

getRowLabelRange(): Excel.Range;

返回

注解

[ API 集:ExcelApi 1.8 ]

load(options)

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

load(options?: Excel.Interfaces.PivotLayoutLoadOptions): Excel.PivotLayout;

参数

options
Excel.Interfaces.PivotLayoutLoadOptions

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

返回

load(propertyNames)

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

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

参数

propertyNames

string | string[]

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

返回

load(propertyNamesAndPaths)

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

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

参数

propertyNamesAndPaths

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

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

返回

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯对象,也可以传递同一类型的另一个 API 对象。

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

参数

properties
Excel.Interfaces.PivotLayoutUpdateData

一个 JavaScript 对象,其属性按同构方式构造为调用方法的对象的属性。

options
OfficeExtension.UpdateOptions

提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止显示错误。

返回

void

set(properties)

基于现有的已加载对象,同时对对象设置多个属性。

set(properties: Excel.PivotLayout): void;

参数

properties
Excel.PivotLayout

返回

void

toJSON()

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

toJSON(): Excel.Interfaces.PivotLayoutData;

返回