Excel.PivotTable class

Excel のピボットテーブルを表します。 ピボットテーブル オブジェクト モデルの詳細については、「 Excel JavaScript API を使用したピボットテーブルの操作」を参照してください。

Extends

注釈

[ API セット: ExcelApi 1.3 ]

プロパティ

allowMultipleFiltersPerField

ピボットテーブルで、テーブル内の特定のピボットフィールドに対して複数のピボットフィルターを適用できるかどうかを指定します。

columnHierarchies

ピボットテーブルの列ピボット階層。

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

dataHierarchies

ピボットテーブルのデータ ピボット階層。

enableDataValueEditing

ピボットテーブルでデータ本文の値をユーザーが編集できるかどうかを指定します。

filterHierarchies

ピボットテーブルのフィルター ピボット階層。

hierarchies

ピボットテーブルのピボット階層。

id

ピボットテーブルの ID。

layout

ピボットテーブルのレイアウトとビジュアル構造を記述する PivotLayout。

name

ピボットテーブルの名前。

refreshOnOpen

ブックが開いたときにピボットテーブルを更新するかどうかを指定します。 UI の [読み込み時に更新] 設定に対応します。

rowHierarchies

ピボットテーブルの行ピボット階層。

useCustomSortLists

並べ替え時にピボットテーブルでカスタム リストを使用するかどうかを指定します。

worksheet

現在のピボットテーブルを含んでいるワークシート。

メソッド

delete()

ピボットテーブルを削除します。

getDataSourceString()

ピボットテーブルのデータ ソースの文字列表現を返します。 このメソッドは現在、テーブルオブジェクトと範囲オブジェクトの文字列表現をサポートしています。 それ以外の場合は、空の文字列を返します。

getDataSourceType()

ピボットテーブルのデータ ソースの種類を取得します。

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

refresh()

ピボットテーブルを更新します。

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出 toJSON します)。元の Excel.PivotTable オブジェクトは API オブジェクトですが、メソッドは、元の toJSON オブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト (として Excel.Interfaces.PivotTableData型指定) を返します。

プロパティの詳細

allowMultipleFiltersPerField

ピボットテーブルで、テーブル内の特定のピボットフィールドに対して複数のピボットフィルターを適用できるかどうかを指定します。

allowMultipleFiltersPerField: boolean;

プロパティ値

boolean

注釈

[ API セット: ExcelApi 1.12 ]

columnHierarchies

ピボットテーブルの列ピボット階層。

readonly columnHierarchies: Excel.RowColumnPivotHierarchyCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

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

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

    // Check if the PivotTable already has a column.
    const column = pivotTable.columnHierarchies.getItemOrNullObject("Farm");
    column.load("id");
    await context.sync();

    if (column.isNullObject) {
        // Adding the farm column to the column hierarchy automatically removes it from the row hierarchy.
        pivotTable.columnHierarchies.add(pivotTable.hierarchies.getItem("Farm"));
    } else {
        pivotTable.columnHierarchies.remove(column);
    }

    await context.sync();
});

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

dataHierarchies

ピボットテーブルのデータ ピボット階層。

readonly dataHierarchies: Excel.DataPivotHierarchyCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

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

await Excel.run(async (context) => {
    const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");
    pivotTable.dataHierarchies.add(pivotTable.hierarchies.getItem("Crates Sold at Farm"));
    pivotTable.dataHierarchies.add(pivotTable.hierarchies.getItem("Crates Sold Wholesale"));

    await context.sync();
});

enableDataValueEditing

ピボットテーブルでデータ本文の値をユーザーが編集できるかどうかを指定します。

enableDataValueEditing: boolean;

プロパティ値

boolean

注釈

[ API セット: ExcelApi 1.9 ]

filterHierarchies

ピボットテーブルのフィルター ピボット階層。

readonly filterHierarchies: Excel.FilterPivotHierarchyCollection;

プロパティ値

注釈

[ 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

async function filter(functionType: Excel.AggregationFunction) {
    await Excel.run(async (context) => {
        const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");
        const filters = pivotTable.filterHierarchies;
        const filter = filters.getItemOrNullObject("Classification");
        filter.load();
        await context.sync();

        // Add the Classification hierarchy to the filter, if it's not already there.
        if (filter.isNullObject) {
            filters.add(pivotTable.hierarchies.getItem("Classification"));
            await context.sync();
        }
    });
}

hierarchies

ピボットテーブルのピボット階層。

readonly hierarchies: Excel.PivotHierarchyCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

id

ピボットテーブルの ID。

readonly id: string;

プロパティ値

string

注釈

[ API セット: ExcelApi 1.5 ]

layout

ピボットテーブルのレイアウトとビジュアル構造を記述する PivotLayout。

readonly layout: Excel.PivotLayout;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

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

await Excel.run(async (context) => {
    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);
});

name

ピボットテーブルの名前。

name: string;

プロパティ値

string

注釈

[ API セット: ExcelApi 1.3 ]

refreshOnOpen

ブックが開いたときにピボットテーブルを更新するかどうかを指定します。 UI の [読み込み時に更新] 設定に対応します。

refreshOnOpen: boolean;

プロパティ値

boolean

注釈

[ API セット: ExcelApi 1.13 ]

rowHierarchies

ピボットテーブルの行ピボット階層。

readonly rowHierarchies: Excel.RowColumnPivotHierarchyCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.8 ]

useCustomSortLists

並べ替え時にピボットテーブルでカスタム リストを使用するかどうかを指定します。

useCustomSortLists: boolean;

プロパティ値

boolean

注釈

[ API セット: ExcelApi 1.9 ]

worksheet

現在のピボットテーブルを含んでいるワークシート。

readonly worksheet: Excel.Worksheet;

プロパティ値

注釈

[ API セット: ExcelApi 1.3 ]

メソッドの詳細

delete()

ピボットテーブルを削除します。

delete(): void;

戻り値

void

注釈

[ API セット: ExcelApi 1.8 ]

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

await Excel.run(async (context) => {
    context.workbook.worksheets.getItem("Pivot").pivotTables.getItem("Farm Sales").delete();

    await context.sync();
});

getDataSourceString()

ピボットテーブルのデータ ソースの文字列表現を返します。 このメソッドは現在、テーブルオブジェクトと範囲オブジェクトの文字列表現をサポートしています。 それ以外の場合は、空の文字列を返します。

getDataSourceString(): OfficeExtension.ClientResult<string>;

戻り値

注釈

[ API セット: ExcelApi 1.15 ]

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

// This function logs information about the data source of a PivotTable.
await Excel.run(async (context) => {
  const worksheet = context.workbook.worksheets.getItem("TotalPivot");
  const pivotTable = worksheet.pivotTables.getItem("All Farm Sales");

  // Retrieve the type and string representation of the data source of the PivotTable.
  const pivotTableDataSourceType = pivotTable.getDataSourceType();
  const pivotTableDataSourceString = pivotTable.getDataSourceString();
  await context.sync();

  // Log the data source information.
  console.log("Data source: " + pivotTableDataSourceString.value);
  console.log("Source type: " + pivotTableDataSourceType.value);
});

getDataSourceType()

ピボットテーブルのデータ ソースの種類を取得します。

getDataSourceType(): OfficeExtension.ClientResult<Excel.DataSourceType>;

戻り値

注釈

[ API セット: ExcelApi 1.15 ]

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

// This function logs information about the data source of a PivotTable.
await Excel.run(async (context) => {
  const worksheet = context.workbook.worksheets.getItem("TotalPivot");
  const pivotTable = worksheet.pivotTables.getItem("All Farm Sales");

  // Retrieve the type and string representation of the data source of the PivotTable.
  const pivotTableDataSourceType = pivotTable.getDataSourceType();
  const pivotTableDataSourceString = pivotTable.getDataSourceString();
  await context.sync();

  // Log the data source information.
  console.log("Data source: " + pivotTableDataSourceString.value);
  console.log("Source type: " + pivotTableDataSourceType.value);
});

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: Excel.Interfaces.PivotTableLoadOptions): Excel.PivotTable;

パラメーター

options
Excel.Interfaces.PivotTableLoadOptions

読み込むオブジェクトのプロパティのオプションを提供します。

戻り値

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

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

パラメーター

propertyNames

string | string[]

読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。

戻り値

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

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

パラメーター

propertyNamesAndPaths

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

propertyNamesAndPaths.select は、読み込むプロパティを指定するコンマ区切り文字列で propertyNamesAndPaths.expand 、読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。

戻り値

refresh()

ピボットテーブルを更新します。

refresh(): void;

戻り値

void

注釈

[ API セット: ExcelApi 1.3 ]

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

// This function refreshes the "Farm Sales" PivotTable,
// which updates the PivotTable with changes made to the source table.
await Excel.run(async (context) => {
  const pivotTable = context.workbook.pivotTables.getItem("Farm Sales");
  pivotTable.refresh();
  await context.sync();
});

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。

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

パラメーター

properties
Excel.Interfaces.PivotTableUpdateData

メソッドが呼び出されるオブジェクトのプロパティに等形的に構造化されたプロパティを持つ JavaScript オブジェクト。

options
OfficeExtension.UpdateOptions

properties オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。

戻り値

void

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

set(properties: Excel.PivotTable): void;

パラメーター

properties
Excel.PivotTable

戻り値

void

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出 toJSON します)。元の Excel.PivotTable オブジェクトは API オブジェクトですが、メソッドは、元の toJSON オブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト (として Excel.Interfaces.PivotTableData型指定) を返します。

toJSON(): Excel.Interfaces.PivotTableData;

戻り値