ExcelScript.PivotHierarchy interface

Represents the Excel PivotHierarchy.

Remarks

Examples

/**
 * This script creates a PivotTable from an existing table and adds it to a new worksheet.
 * This script assumes there is a table in the current worksheet with columns named "Type" and "Sales".
 */
function main(workbook: ExcelScript.Workbook) {
  // Create a PivotTable based on a table in the current worksheet.
  let sheet = workbook.getActiveWorksheet();
  let table = sheet.getTables()[0];

  // Add the PivotTable to a new worksheet.
  let newSheet = workbook.addWorksheet("Pivot");
  let pivotTable = newSheet.addPivotTable("My Pivot", table, "A1");

  // Add fields to the PivotTable to show "Sales" per "Type".
  pivotTable.addRowHierarchy(pivotTable.getHierarchy("Type"));
  pivotTable.addDataHierarchy(pivotTable.getHierarchy("Sales"));
}

Methods

getFields()

Returns the PivotFields associated with the PivotHierarchy.

getId()

ID of the PivotHierarchy.

getName()

Name of the PivotHierarchy.

getPivotField(name)

Gets a PivotField by name. If the PivotField does not exist, then this method returns undefined.

setName(name)

Name of the PivotHierarchy.

Method Details

getFields()

Returns the PivotFields associated with the PivotHierarchy.

getFields(): PivotField[];

Returns

getId()

ID of the PivotHierarchy.

getId(): string;

Returns

string

getName()

Name of the PivotHierarchy.

getName(): string;

Returns

string

getPivotField(name)

Gets a PivotField by name. If the PivotField does not exist, then this method returns undefined.

getPivotField(name: string): PivotField | undefined;

Parameters

name

string

Name of the PivotField to be retrieved.

Returns

setName(name)

Name of the PivotHierarchy.

setName(name: string): void;

Parameters

name

string

Returns

void