Compartilhar via


ExcelScript.PivotTable interface

Representa uma Tabela Dinâmica do Excel.

Comentários

Exemplos

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

Métodos

addColumnHierarchy(pivotHierarchy)

Adiciona o PivotHierarchy ao eixo atual. Se houver hierarquia em outro lugar na linha, coluna ou eixo de filtro, ele será removido desse local.

addDataHierarchy(pivotHierarchy)

Adiciona o PivotHierarchy ao eixo atual.

addFilterHierarchy(pivotHierarchy)

Adiciona o PivotHierarchy ao eixo atual. Se houver hierarquia em outro lugar na linha, coluna ou eixo de filtro, ele será removido desse local.

addRowHierarchy(pivotHierarchy)

Adiciona o PivotHierarchy ao eixo atual. Se houver hierarquia em outro lugar na linha, coluna ou eixo de filtro, ele será removido desse local.

delete()

Exclui a Tabela Dinâmica.

getAllowMultipleFiltersPerField()

Especifica se a Tabela Dinâmica permite a aplicação de vários PivotFilters em um determinado PivotField na tabela.

getColumnHierarchies()

As hierarquias de pivô da coluna da Tabela Dinâmica.

getColumnHierarchy(name)

Obtém um RowColumnPivotHierarchy por nome. Se o RowColumnPivotHierarchy não existir, esse método retornará undefined.

getDataHierarchies()

As hierarquias dinâmicas de dados da Tabela Dinâmica.

getDataHierarchy(name)

Obtém uma DataPivotHierarchy por nome. Se o DataPivotHierarchy não existir, esse método retornará undefined.

getEnableDataValueEditing()

Especifica se a Tabela Dinâmica permite que valores no corpo dos dados sejam editados pelo usuário.

getFilterHierarchies()

As hierarquias de pivô do filtro da Tabela Dinâmica.

getFilterHierarchy(name)

Obtém um FilterPivotHierarchy por nome. Se o FilterPivotHierarchy não existir, esse método retornará undefined.

getHierarchies()

Hierarquias pivô da Tabela Dinâmica.

getHierarchy(name)

Obtém o PivotHierarchy por nome. Se a PivotHierarchy não existir, esse método retornará undefined.

getId()

ID da Tabela Dinâmica.

getLayout()

O PivotLayout descreve o layout e estrutura visual da Tabela Dinâmica.

getName()

Nome da Tabela Dinâmica.

getRowHierarchies()

As hierarquias de pivô de linha da Tabela Dinâmica.

getRowHierarchy(name)

Obtém um RowColumnPivotHierarchy por nome. Se o RowColumnPivotHierarchy não existir, esse método retornará undefined.

getUseCustomSortLists()

Especifica se a Tabela Dinâmica usa listas personalizadas ao classificar.

getWorksheet()

A planilha que contém a Tabela Dinâmica atual.

refresh()

Atualiza a Tabela Dinâmica.

removeColumnHierarchy(rowColumnPivotHierarchy)

Remove o PivotHierarchy do eixo atual.

removeDataHierarchy(DataPivotHierarchy)

Remove o PivotHierarchy do eixo atual.

removeFilterHierarchy(filterPivotHierarchy)

Remove o PivotHierarchy do eixo atual.

removeRowHierarchy(rowColumnPivotHierarchy)

Remove o PivotHierarchy do eixo atual.

setAllowMultipleFiltersPerField(allowMultipleFiltersPerField)

Especifica se a Tabela Dinâmica permite a aplicação de vários PivotFilters em um determinado PivotField na tabela.

setEnableDataValueEditing(enableDataValueEditing)

Especifica se a Tabela Dinâmica permite que valores no corpo dos dados sejam editados pelo usuário.

setName(name)

Nome da Tabela Dinâmica.

setUseCustomSortLists(useCustomSortLists)

Especifica se a Tabela Dinâmica usa listas personalizadas ao classificar.

Detalhes do método

addColumnHierarchy(pivotHierarchy)

Adiciona o PivotHierarchy ao eixo atual. Se houver hierarquia em outro lugar na linha, coluna ou eixo de filtro, ele será removido desse local.

addColumnHierarchy(
            pivotHierarchy: PivotHierarchy
        ): RowColumnPivotHierarchy;

Parâmetros

Retornos

Exemplos

/**
 * This script adds a row hierarchy to the PivotTable on the current worksheet.
 * This assumes the source data has columns named 
 * "Type", "Classification", and "Sales".
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the PivotTable on the current worksheet.
  let sheet = workbook.getActiveWorksheet();
  let pivotTable = sheet.getPivotTables()[0];

  // Add the field "Type" to the PivotTable as a row hierarchy.
  pivotTable.addRowHierarchy(pivotTable.getHierarchy("Type"));

  // Add the field "Classification" to the PivotTable as a column hierarchy.
  pivotTable.addColumnHierarchy(pivotTable.getHierarchy("Classification"));

  // Add the field "Sales" to the PivotTable as a data hierarchy.
  // By default, this displays the sums of the values in "Sales" based on the "Type".
  pivotTable.addDataHierarchy(pivotTable.getHierarchy("Sales"));
}

addDataHierarchy(pivotHierarchy)

Adiciona o PivotHierarchy ao eixo atual.

addDataHierarchy(pivotHierarchy: PivotHierarchy): DataPivotHierarchy;

Parâmetros

Retornos

Exemplos

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

addFilterHierarchy(pivotHierarchy)

Adiciona o PivotHierarchy ao eixo atual. Se houver hierarquia em outro lugar na linha, coluna ou eixo de filtro, ele será removido desse local.

addFilterHierarchy(
            pivotHierarchy: PivotHierarchy
        ): FilterPivotHierarchy;

Parâmetros

Retornos

Exemplos

/**
 * This script adds a manual filter to a PivotTable. 
 */
function main(workbook: ExcelScript.Workbook)
{
  // Get the first PivotTable in the workbook.
  const pivot = workbook.getPivotTables()[0];

  // Get the hierarchy to use as the filter.
  const location = pivot.getHierarchy("Location");

  // Use "Location" as the FilterHierarchy.
  pivot.addFilterHierarchy(location);

  // Select items for the filter.
  // Note that hierarchies and fields have a 1:1 relationship in Excel,
  // so `getFields()[0]` always gets the correct field.
  location.getFields()[0].applyFilter({
    manualFilter: {
      selectedItems: ["Seattle", "Chicago"]
    }
  });
}

addRowHierarchy(pivotHierarchy)

Adiciona o PivotHierarchy ao eixo atual. Se houver hierarquia em outro lugar na linha, coluna ou eixo de filtro, ele será removido desse local.

addRowHierarchy(
            pivotHierarchy: PivotHierarchy
        ): RowColumnPivotHierarchy;

Parâmetros

Retornos

Exemplos

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

delete()

Exclui a Tabela Dinâmica.

delete(): void;

Retornos

void

getAllowMultipleFiltersPerField()

Especifica se a Tabela Dinâmica permite a aplicação de vários PivotFilters em um determinado PivotField na tabela.

getAllowMultipleFiltersPerField(): boolean;

Retornos

boolean

getColumnHierarchies()

As hierarquias de pivô da coluna da Tabela Dinâmica.

getColumnHierarchies(): RowColumnPivotHierarchy[];

Retornos

getColumnHierarchy(name)

Obtém um RowColumnPivotHierarchy por nome. Se o RowColumnPivotHierarchy não existir, esse método retornará undefined.

getColumnHierarchy(name: string): RowColumnPivotHierarchy | undefined;

Parâmetros

name

string

Nome da RowColumnPivotHierarchy a ser recuperada.

Retornos

getDataHierarchies()

As hierarquias dinâmicas de dados da Tabela Dinâmica.

getDataHierarchies(): DataPivotHierarchy[];

Retornos

getDataHierarchy(name)

Obtém uma DataPivotHierarchy por nome. Se o DataPivotHierarchy não existir, esse método retornará undefined.

getDataHierarchy(name: string): DataPivotHierarchy | undefined;

Parâmetros

name

string

Nome do DataPivotHierarchy a ser recuperado.

Retornos

getEnableDataValueEditing()

Especifica se a Tabela Dinâmica permite que valores no corpo dos dados sejam editados pelo usuário.

getEnableDataValueEditing(): boolean;

Retornos

boolean

getFilterHierarchies()

As hierarquias de pivô do filtro da Tabela Dinâmica.

getFilterHierarchies(): FilterPivotHierarchy[];

Retornos

getFilterHierarchy(name)

Obtém um FilterPivotHierarchy por nome. Se o FilterPivotHierarchy não existir, esse método retornará undefined.

getFilterHierarchy(name: string): FilterPivotHierarchy | undefined;

Parâmetros

name

string

Nome do FilterPivotHierarchy a ser recuperado.

Retornos

getHierarchies()

Hierarquias pivô da Tabela Dinâmica.

getHierarchies(): PivotHierarchy[];

Retornos

getHierarchy(name)

Obtém o PivotHierarchy por nome. Se a PivotHierarchy não existir, esse método retornará undefined.

getHierarchy(name: string): PivotHierarchy | undefined;

Parâmetros

name

string

Nome do PivotHierarchy a ser recuperado.

Retornos

getId()

ID da Tabela Dinâmica.

getId(): string;

Retornos

string

getLayout()

O PivotLayout descreve o layout e estrutura visual da Tabela Dinâmica.

getLayout(): PivotLayout;

Retornos

Exemplos

/**
 * 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);
}

getName()

Nome da Tabela Dinâmica.

getName(): string;

Retornos

string

getRowHierarchies()

As hierarquias de pivô de linha da Tabela Dinâmica.

getRowHierarchies(): RowColumnPivotHierarchy[];

Retornos

getRowHierarchy(name)

Obtém um RowColumnPivotHierarchy por nome. Se o RowColumnPivotHierarchy não existir, esse método retornará undefined.

getRowHierarchy(name: string): RowColumnPivotHierarchy | undefined;

Parâmetros

name

string

Nome da RowColumnPivotHierarchy a ser recuperada.

Retornos

Exemplos

/**
 * This sample sorts the rows of a PivotTable.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get an existing PivotTable.
  const pivotTable = workbook.getPivotTable("Farm Sales");

  // Get the data hierarchy to use as the basis of the sort.
  const valueFieldToSortOn = pivotTable.getDataHierarchy("Sum of Crates Sold Wholesale");

  // Get the row to sort.
  const rowToSort = pivotTable.getRowHierarchy("Farm");

  // Sort the "Farm" row's only field by the values in "Sum of Crates Sold Wholesale".
  rowToSort.getFields()[0].sortByValues(ExcelScript.SortBy.descending, valueFieldToSortOn);
}

getUseCustomSortLists()

Especifica se a Tabela Dinâmica usa listas personalizadas ao classificar.

getUseCustomSortLists(): boolean;

Retornos

boolean

getWorksheet()

A planilha que contém a Tabela Dinâmica atual.

getWorksheet(): Worksheet;

Retornos

refresh()

Atualiza a Tabela Dinâmica.

refresh(): void;

Retornos

void

removeColumnHierarchy(rowColumnPivotHierarchy)

Remove o PivotHierarchy do eixo atual.

removeColumnHierarchy(
            rowColumnPivotHierarchy: RowColumnPivotHierarchy
        ): void;

Parâmetros

rowColumnPivotHierarchy
ExcelScript.RowColumnPivotHierarchy

Retornos

void

removeDataHierarchy(DataPivotHierarchy)

Remove o PivotHierarchy do eixo atual.

removeDataHierarchy(DataPivotHierarchy: DataPivotHierarchy): void;

Parâmetros

DataPivotHierarchy
ExcelScript.DataPivotHierarchy

Retornos

void

removeFilterHierarchy(filterPivotHierarchy)

Remove o PivotHierarchy do eixo atual.

removeFilterHierarchy(filterPivotHierarchy: FilterPivotHierarchy): void;

Parâmetros

filterPivotHierarchy
ExcelScript.FilterPivotHierarchy

Retornos

void

removeRowHierarchy(rowColumnPivotHierarchy)

Remove o PivotHierarchy do eixo atual.

removeRowHierarchy(
            rowColumnPivotHierarchy: RowColumnPivotHierarchy
        ): void;

Parâmetros

rowColumnPivotHierarchy
ExcelScript.RowColumnPivotHierarchy

Retornos

void

setAllowMultipleFiltersPerField(allowMultipleFiltersPerField)

Especifica se a Tabela Dinâmica permite a aplicação de vários PivotFilters em um determinado PivotField na tabela.

setAllowMultipleFiltersPerField(
            allowMultipleFiltersPerField: boolean
        ): void;

Parâmetros

allowMultipleFiltersPerField

boolean

Retornos

void

setEnableDataValueEditing(enableDataValueEditing)

Especifica se a Tabela Dinâmica permite que valores no corpo dos dados sejam editados pelo usuário.

setEnableDataValueEditing(enableDataValueEditing: boolean): void;

Parâmetros

enableDataValueEditing

boolean

Retornos

void

setName(name)

Nome da Tabela Dinâmica.

setName(name: string): void;

Parâmetros

name

string

Retornos

void

setUseCustomSortLists(useCustomSortLists)

Especifica se a Tabela Dinâmica usa listas personalizadas ao classificar.

setUseCustomSortLists(useCustomSortLists: boolean): void;

Parâmetros

useCustomSortLists

boolean

Retornos

void