ExcelScript.PivotLayout interface

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

方法

getAutoFormat()

指定在刷新时还是移动字段时自动设置格式设置格式。

getBodyAndTotalRange()

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

getColumnLabelRange()

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

getDataHierarchy(cell)

获取 DataHierarchy,它用于计算数据透视表中指定区域内的值。

getEnableFieldList()

指定是否可以在 UI 中显示字段列表。

getFilterAxisRange()

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

getLayoutType()

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

getPreserveFormatting()

指定在通过透视、排序或更改页字段项等操作刷新或重新计算报表时是否保留格式。

getRange()

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

getRowLabelRange()

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

getShowColumnGrandTotals()

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

getShowRowGrandTotals()

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

getSubtotalLocation()

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

setAutoFormat(autoFormat)

指定在刷新时还是移动字段时自动设置格式设置格式。

setAutoSortOnCell(cell, sortBy)

将数据透视表设置为使用指定的单元格设置自动排序,以自动选择排序的所有条件和上下文。 这与从 UI 应用自动排序的行为相同。

setEnableFieldList(enableFieldList)

指定是否可以在 UI 中显示字段列表。

setLayoutType(layoutType)

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

setPreserveFormatting(preserveFormatting)

指定在通过透视、排序或更改页字段项等操作刷新或重新计算报表时是否保留格式。

setShowColumnGrandTotals(showColumnGrandTotals)

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

setShowRowGrandTotals(showRowGrandTotals)

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

setSubtotalLocation(subtotalLocation)

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

方法详细信息

getAutoFormat()

指定在刷新时还是移动字段时自动设置格式设置格式。

getAutoFormat(): boolean;

返回

boolean

getBodyAndTotalRange()

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

getBodyAndTotalRange(): Range;

返回

示例

/**
 * This sample finds the first PivotTable in the workbook and logs the values in the "Grand Total" cells.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first PivotTable in the workbook.
  let pivotTable = workbook.getPivotTables()[0];

  // Get the names of each data column in the PivotTable.
  let pivotColumnLabelRange = pivotTable.getLayout().getColumnLabelRange();

  // Get the range displaying the pivoted data.
  let pivotDataRange = pivotTable.getLayout().getBodyAndTotalRange();

  // Get the range with the "grand totals" for the PivotTable columns.
  let grandTotalRange = pivotDataRange.getLastRow();

  // Print each of the "Grand Totals" to the console.
  grandTotalRange.getValues()[0].forEach((column, columnIndex) => {
    console.log(`Grand total of ${pivotColumnLabelRange.getValues()[0][columnIndex]}: ${grandTotalRange.getValues()[0][columnIndex]}`);
    // Example log: "Grand total of Sum of Crates Sold Wholesale: 11000"
  });
}

getColumnLabelRange()

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

getColumnLabelRange(): Range;

返回

getDataHierarchy(cell)

获取 DataHierarchy,它用于计算数据透视表中指定区域内的值。

getDataHierarchy(cell: Range | string): DataPivotHierarchy;

参数

cell

ExcelScript.Range | string

数据透视表数据正文中的单个单元格。

返回

getEnableFieldList()

指定是否可以在 UI 中显示字段列表。

getEnableFieldList(): boolean;

返回

boolean

getFilterAxisRange()

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

getFilterAxisRange(): Range;

返回

getLayoutType()

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

getLayoutType(): PivotLayoutType;

返回

getPreserveFormatting()

指定在通过透视、排序或更改页字段项等操作刷新或重新计算报表时是否保留格式。

getPreserveFormatting(): boolean;

返回

boolean

getRange()

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

getRange(): Range;

返回

getRowLabelRange()

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

getRowLabelRange(): Range;

返回

getShowColumnGrandTotals()

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

getShowColumnGrandTotals(): boolean;

返回

boolean

getShowRowGrandTotals()

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

getShowRowGrandTotals(): boolean;

返回

boolean

getSubtotalLocation()

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

getSubtotalLocation(): SubtotalLocationType;

返回

setAutoFormat(autoFormat)

指定在刷新时还是移动字段时自动设置格式设置格式。

setAutoFormat(autoFormat: boolean): void;

参数

autoFormat

boolean

返回

void

setAutoSortOnCell(cell, sortBy)

将数据透视表设置为使用指定的单元格设置自动排序,以自动选择排序的所有条件和上下文。 这与从 UI 应用自动排序的行为相同。

setAutoSortOnCell(cell: Range | string, sortBy: SortBy): void;

参数

cell

ExcelScript.Range | string

一个单元格,用于获取用于应用自动排序的条件。

sortBy
ExcelScript.SortBy

排序的方向。

返回

void

setEnableFieldList(enableFieldList)

指定是否可以在 UI 中显示字段列表。

setEnableFieldList(enableFieldList: boolean): void;

参数

enableFieldList

boolean

返回

void

setLayoutType(layoutType)

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

setLayoutType(layoutType: PivotLayoutType): void;

参数

返回

void

示例

/**
 * This script sets the layout of the "Farms Sales" PivotTable to the "tabular"
 * setting. This places the fields from the Rows area in separate columns.
 */ 
function main(workbook: ExcelScript.Workbook) {
  // Get the PivotTable named "Farm Sales".
  const pivot = workbook.getPivotTable("Farm Sales");

  // Get the PivotLayout object.
  const layout = pivot.getLayout();

  // Set the layout type to "tabular".
  layout.setLayoutType(ExcelScript.PivotLayoutType.tabular);
}

setPreserveFormatting(preserveFormatting)

指定在通过透视、排序或更改页字段项等操作刷新或重新计算报表时是否保留格式。

setPreserveFormatting(preserveFormatting: boolean): void;

参数

preserveFormatting

boolean

返回

void

setShowColumnGrandTotals(showColumnGrandTotals)

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

setShowColumnGrandTotals(showColumnGrandTotals: boolean): void;

参数

showColumnGrandTotals

boolean

返回

void

setShowRowGrandTotals(showRowGrandTotals)

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

setShowRowGrandTotals(showRowGrandTotals: boolean): void;

参数

showRowGrandTotals

boolean

返回

void

setSubtotalLocation(subtotalLocation)

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

setSubtotalLocation(subtotalLocation: SubtotalLocationType): void;

参数

返回

void

示例

/**
 * This script displays group subtotals of the "Farms Sales" PivotTable.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the PivotTable named "Farm Sales".
  const pivot = workbook.getPivotTable("Farm Sales");

  // Get the PivotLayout object.
  const layout = pivot.getLayout();

  // Show all the subtotals at the bottom of each group.
  layout.setSubtotalLocation(ExcelScript.SubtotalLocationType.atBottom);
}