Share via


Excel.Workbook class

ブックは、ワークシート、テーブル、範囲などの関連するブック オブジェクトを含む最上位のオブジェクトです。 ブック オブジェクト モデルの詳細については、「 Excel JavaScript API を使用してブックを操作する」を参照してください。

Extends

注釈

[ API セット: ExcelApi 1.1 ]

プロパティ

application

このブックを含む Excel アプリケーション インスタンスを表します。

bindings

ブックの一部であるバインドのコレクションを表します。

context

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

customXmlParts

このブックに含まれるカスタム XML パーツのコレクションを表します。

dataConnections

ブック内のすべてのデータ接続を表します。

functions

計算に使用できるワークシート関数のコレクションを表します。

name

ブックの名前を取得します。

names

ブックスコープの名前付き項目 (名前付き範囲と定数) のコレクションを表します。

pivotTables

ブックに関連付けられているピボットテーブルのコレクションを表します。

properties

ブックのプロパティを取得します。

protection

ブックの保護オブジェクトを返します。

readOnly

ブックが true 読み取り専用モードで開いている場合は を返します。

settings

ブックに関連付けられている設定のコレクションを表します。

styles

ブックに関連付けられているスタイルのコレクションを表します。

tables

ブックに関連付けられているテーブルのコレクションを表します。

worksheets

ブックに関連付けられているワークシートのコレクションを表します。

メソッド

getActiveCell()

ブックで現在アクティブなセルを取得します。

getSelectedRange()

ブックから現在選択されている 1 つの範囲を取得します。 複数の範囲が選択されている場合、このメソッドはエラーをスローします。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

set(properties, options)

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

set(properties)

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

toJSON()

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

イベント

onSelectionChanged

ドキュメント内で選択が変更されるときに発生します。

プロパティの詳細

application

このブックを含む Excel アプリケーション インスタンスを表します。

readonly application: Excel.Application;

プロパティ値

注釈

[ API セット: ExcelApi 1.1 ]

bindings

ブックの一部であるバインドのコレクションを表します。

readonly bindings: Excel.BindingCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.1 ]

context

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

context: RequestContext;

プロパティ値

customXmlParts

このブックに含まれるカスタム XML パーツのコレクションを表します。

readonly customXmlParts: Excel.CustomXmlPartCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.5 ]

dataConnections

ブック内のすべてのデータ接続を表します。

readonly dataConnections: Excel.DataConnectionCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.7 ]

functions

計算に使用できるワークシート関数のコレクションを表します。

readonly functions: Excel.Functions;

プロパティ値

注釈

[ API セット: ExcelApi 1.2 ]

name

ブックの名前を取得します。

readonly name: string;

プロパティ値

string

注釈

[ API セット: ExcelApi 1.7 ]

names

ブックスコープの名前付き項目 (名前付き範囲と定数) のコレクションを表します。

readonly names: Excel.NamedItemCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.1 ]

pivotTables

ブックに関連付けられているピボットテーブルのコレクションを表します。

readonly pivotTables: Excel.PivotTableCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.3 ]

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

await Excel.run(async (context) => {
  // Get the names of all the PivotTables in the workbook.
  const pivotTables = context.workbook.pivotTables;
  pivotTables.load("name");
  await context.sync();

  // Display the names in the console.
  console.log("PivotTables in the workbook:")
  pivotTables.items.forEach((pivotTable) => {
    console.log(`\t${pivotTable.name}`);
  });
});

properties

ブックのプロパティを取得します。

readonly properties: Excel.DocumentProperties;

プロパティ値

注釈

[ API セット: ExcelApi 1.7 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/26-document/properties.yaml

await Excel.run(async (context) => {
    let titleValue = "Excel document properties API";
    let subjectValue = "Set and get document properties";
    let keywordsValue = "Set and get operations";
    let commentsValue = "This is an Excel document properties API code sample";
    let categoryValue = "Office Add-ins";
    let managerValue = "John";
    let companyValue = "Microsoft";

    let docProperties = context.workbook.properties;

    // Set the writeable document properties.
    docProperties.title = titleValue;
    docProperties.subject = subjectValue;
    docProperties.keywords = keywordsValue;
    docProperties.comments = commentsValue;
    docProperties.category = categoryValue;
    docProperties.manager = managerValue;
    docProperties.company = companyValue;

    await context.sync();

    console.log("Set the following document properties: title, subject, keywords, comments, category, manager, company.");
});

protection

ブックの保護オブジェクトを返します。

readonly protection: Excel.WorkbookProtection;

プロパティ値

注釈

[ API セット: ExcelApi 1.7 ]

readOnly

ブックが true 読み取り専用モードで開いている場合は を返します。

readonly readOnly: boolean;

プロパティ値

boolean

注釈

[ API セット: ExcelApi 1.8 ]

settings

ブックに関連付けられている設定のコレクションを表します。

readonly settings: Excel.SettingCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.4 ]

styles

ブックに関連付けられているスタイルのコレクションを表します。

readonly styles: Excel.StyleCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.7 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/style.yaml

await Excel.run(async (context) => {
    let styles = context.workbook.styles;

    // Add a new style to the style collection.
    // Styles is in the Home tab ribbon.
    styles.add("Diagonal Orientation Style");
          
    let newStyle = styles.getItem("Diagonal Orientation Style");
    
    // The "Diagonal Orientation Style" properties.
    newStyle.textOrientation = 38;
    newStyle.autoIndent = true;
    newStyle.includeProtection = true;
    newStyle.shrinkToFit = true;
    newStyle.locked = false;
    
    await context.sync();

    console.log("Successfully added a new style with diagonal orientation to the Home tab ribbon.");
});

tables

ブックに関連付けられているテーブルのコレクションを表します。

readonly tables: Excel.TableCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.1 ]

worksheets

ブックに関連付けられているワークシートのコレクションを表します。

readonly worksheets: Excel.WorksheetCollection;

プロパティ値

注釈

[ API セット: ExcelApi 1.1 ]

メソッドの詳細

getActiveCell()

ブックで現在アクティブなセルを取得します。

getActiveCell(): Excel.Range;

戻り値

注釈

[ API セット: ExcelApi 1.7 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/50-workbook/workbook-get-active-cell.yaml

await Excel.run(async (context) => {

    let myWorkbook = context.workbook;
    let activeCell = myWorkbook.getActiveCell();
    activeCell.load("address");

    await context.sync();
    
    console.log("The active cell is " + activeCell.address);
});

getSelectedRange()

ブックから現在選択されている 1 つの範囲を取得します。 複数の範囲が選択されている場合、このメソッドはエラーをスローします。

getSelectedRange(): Excel.Range;

戻り値

注釈

[ API セット: ExcelApi 1.1 ]

await Excel.run(async (context) => { 
    const selectedRange = context.workbook.getSelectedRange();
    selectedRange.load('address');
    await context.sync();
    console.log(selectedRange.address);
});

load(options)

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

load(options?: Excel.Interfaces.WorkbookLoadOptions): Excel.Workbook;

パラメーター

options
Excel.Interfaces.WorkbookLoadOptions

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

戻り値

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

戻り値

set(properties, options)

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

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

パラメーター

properties
Excel.Interfaces.WorkbookUpdateData

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

options
OfficeExtension.UpdateOptions

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

戻り値

void

set(properties)

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

set(properties: Excel.Workbook): void;

パラメーター

properties
Excel.Workbook

戻り値

void

toJSON()

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

toJSON(): Excel.Interfaces.WorkbookData;

戻り値

イベントの詳細

onSelectionChanged

ドキュメント内で選択が変更されるときに発生します。

readonly onSelectionChanged: OfficeExtension.EventHandlers<Excel.SelectionChangedEventArgs>;

イベントの種類

注釈

[ API セット: ExcelApi 1.2 ]