Word.Section class

Word 文書内のセクションを表します。

Extends

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/insert-section-breaks.yaml

// Inserts a section break on the next page.
await Word.run(async (context) => {
  const body = context.document.body;
  body.insertBreak(Word.BreakType.sectionNext, Word.InsertLocation.end);

  await context.sync();

  console.log("Inserted section break on next page");
});

プロパティ

body

セクションの body オブジェクトを取得します。 これには、ヘッダー/フッターやその他のセクション メタデータは含まれません。

context

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

メソッド

getFooter(type)

セクションのフッターの 1 つを取得します。

getFooter(typeString)

セクションのフッターの 1 つを取得します。

getHeader(type)

セクションのヘッダーの 1 つを取得します。

getHeader(typeString)

セクションのヘッダーの 1 つを取得します。

getNext()

次のセクションを取得します。 このセクションが最後の ItemNotFound セクションである場合は、エラーをスローします。

getNextOrNullObject()

次のセクションを取得します。 このセクションが最後のセクションの場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

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します)。一方、元のWord。Section オブジェクトは API オブジェクトです。メソッドは、元のtoJSONオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト (としてWord.Interfaces.SectionData型指定) を返します。

track()

ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで .sync 使用していて、".run" バッチのシーケンシャル実行の外部で使用していて、プロパティを設定するとき、またはオブジェクトのメソッドを呼び出すときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。

untrack()

前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す context.sync() 必要があります。

プロパティの詳細

body

セクションの body オブジェクトを取得します。 これには、ヘッダー/フッターやその他のセクション メタデータは含まれません。

readonly body: Word.Body;

プロパティ値

注釈

[ API セット: WordApi 1.1 ]

context

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

context: RequestContext;

プロパティ値

メソッドの詳細

getFooter(type)

セクションのフッターの 1 つを取得します。

getFooter(type: Word.HeaderFooterType): Word.Body;

パラメーター

type
Word.HeaderFooterType

必須です。 返されるフッターの型。 この値は、'Primary'、'FirstPage'、または 'EvenPages' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy sectionsCollection object.
    const mySections = context.document.sections;
    
    // Queue a command to load the sections.
    mySections.load('body/style');
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
        
    // Create a proxy object the primary footer of the first section.
    // Note that the footer is a body object.
    const myFooter = mySections.items[0].getFooter(Word.HeaderFooterType.primary);
    
    // Queue a command to insert text at the end of the footer.
    myFooter.insertText("This is a footer.", Word.InsertLocation.end);
    
    // Queue a command to wrap the header in a content control.
    myFooter.insertContentControl();
                            
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    console.log("Added a footer to the first section.");   
});  

getFooter(typeString)

セクションのフッターの 1 つを取得します。

getFooter(typeString: "Primary" | "FirstPage" | "EvenPages"): Word.Body;

パラメーター

typeString

"Primary" | "FirstPage" | "EvenPages"

必須です。 返されるフッターの型。 この値は、'Primary'、'FirstPage'、または 'EvenPages' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-header-and-footer.yaml

await Word.run(async (context) => {
  context.document.sections
    .getFirst()
    .getFooter("Primary")
    .insertParagraph("This is a primary footer.", "End");

  await context.sync();
});

getHeader(type)

セクションのヘッダーの 1 つを取得します。

getHeader(type: Word.HeaderFooterType): Word.Body;

パラメーター

type
Word.HeaderFooterType

必須です。 返されるヘッダーの型。 この値は、'Primary'、'FirstPage'、または 'EvenPages' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/25-paragraph/insert-header-and-footer.yaml

await Word.run(async (context) => {
  context.document.sections
    .getFirst()
    .getHeader(Word.HeaderFooterType.primary)
    .insertParagraph("This is a primary header.", "End");

  await context.sync();
});

getHeader(typeString)

セクションのヘッダーの 1 つを取得します。

getHeader(typeString: "Primary" | "FirstPage" | "EvenPages"): Word.Body;

パラメーター

typeString

"Primary" | "FirstPage" | "EvenPages"

必須です。 返されるヘッダーの型。 この値は、'Primary'、'FirstPage'、または 'EvenPages' である必要があります。

戻り値

注釈

[ API セット: WordApi 1.1 ]

// Run a batch operation against the Word object model.
await Word.run(async (context) => {
    
    // Create a proxy sectionsCollection object.
    const mySections = context.document.sections;
    
    // Queue a command to load the sections.
    mySections.load('body/style');
    
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    
    // Create a proxy object the primary header of the first section.
    // Note that the header is a body object.
    const myHeader = mySections.items[0].getHeader("Primary");
    
    // Queue a command to insert text at the end of the header.
    myHeader.insertText("This is a header.", Word.InsertLocation.end);
    
    // Queue a command to wrap the header in a content control.
    myHeader.insertContentControl();
                            
    // Synchronize the document state by executing the queued commands, 
    // and return a promise to indicate task completion.
    await context.sync();
    console.log("Added a header to the first section.");
});  

getNext()

次のセクションを取得します。 このセクションが最後の ItemNotFound セクションである場合は、エラーをスローします。

getNext(): Word.Section;

戻り値

注釈

[ API セット: WordApi 1.3 ]

getNextOrNullObject()

次のセクションを取得します。 このセクションが最後のセクションの場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObjecttrue返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。

getNextOrNullObject(): Word.Section;

戻り値

注釈

[ API セット: WordApi 1.3 ]

load(options)

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

load(options?: Word.Interfaces.SectionLoadOptions): Word.Section;

パラメーター

options
Word.Interfaces.SectionLoadOptions

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

戻り値

load(propertyNames)

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

load(propertyNames?: string | string[]): Word.Section;

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.Section;

パラメーター

propertyNamesAndPaths

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

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

戻り値

set(properties, options)

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

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

パラメーター

properties
Word.Interfaces.SectionUpdateData

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

options
OfficeExtension.UpdateOptions

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

戻り値

void

set(properties)

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

set(properties: Word.Section): void;

パラメーター

properties
Word.Section

戻り値

void

toJSON()

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

toJSON(): Word.Interfaces.SectionData;

戻り値

track()

ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで .sync 使用していて、".run" バッチのシーケンシャル実行の外部で使用していて、プロパティを設定するとき、またはオブジェクトのメソッドを呼び出すときに "InvalidObjectPath" エラーが発生する場合は、オブジェクトが最初に作成されたときに追跡対象のオブジェクト コレクションにオブジェクトを追加する必要があります。 このオブジェクトがコレクションの一部である場合は、親コレクションも追跡する必要があります。

track(): Word.Section;

戻り値

untrack()

前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す context.sync() 必要があります。

untrack(): Word.Section;

戻り値