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: Word.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 オブジェクトを取得します。 これには、ヘッダー、フッター、およびその他のセクション メタデータは含まれません。

borders

セクション内のすべての罫線を表す BorderUniversalCollection オブジェクトを返します。

context

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

pageSetup

セクションに関連付けられている PageSetup オブジェクトを返します。

protectedForForms

セクションをフォームに対して保護するかどうかを指定します。

メソッド

getFooter(type)

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

getFooter(type)

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

getHeader(type)

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

getHeader(type)

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

getNext()

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

getNextOrNullObject()

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

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

set(properties, options)

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

set(properties)

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

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、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

borders

セクション内のすべての罫線を表す BorderUniversalCollection オブジェクトを返します。

readonly borders: Word.BorderUniversalCollection;

プロパティ値

注釈

API セット: WordApiDesktop 1.3

context

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

context: RequestContext;

プロパティ値

pageSetup

セクションに関連付けられている PageSetup オブジェクトを返します。

readonly pageSetup: Word.PageSetup;

プロパティ値

注釈

API セット: WordApiDesktop 1.3

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

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

  // Configure document-wide page settings for a report that will be printed and bound.
  const pageSetup: Word.PageSetup = context.document.pageSetup;
  pageSetup.set({
    paperSize: Word.PaperSize.letter,
    orientation: Word.PageOrientation.portrait,
    topMargin: 72,
    bottomMargin: 72,
    leftMargin: 90,
    rightMargin: 72,
    gutter: 18,
    gutterPosition: Word.GutterPosition.left,
    mirrorMargins: true,
    oddAndEvenPagesHeaderFooter: true
  });

  const sections: Word.SectionCollection = context.document.sections;
  sections.load("items");
  await context.sync();

  // Start the main chapter on an odd-numbered page so it appears on the right in a bound document.
  const chapterPageSetup: Word.PageSetup = sections.items[1].pageSetup;
  chapterPageSetup.sectionStart = Word.SectionStart.oddPage;
  chapterPageSetup.differentFirstPageHeaderFooter = true;

  // Keep the appendix in a separate section, but let it begin on the current page.
  sections.items[2].pageSetup.sectionStart = Word.SectionStart.continuous;

  await context.sync();
  console.log("Applied print and binding settings to the report.");
});

protectedForForms

セクションをフォームに対して保護するかどうかを指定します。

protectedForForms: boolean;

プロパティ値

boolean

注釈

API セット: WordApiDesktop 1.3

メソッドの詳細

getFooter(type)

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

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

パラメーター

type
Word.HeaderFooterType

返されるフッターの型。 この値には、 primaryfirstPageevenPages のいずれかを指定する必要があります。

返品

注釈

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(type)

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

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

パラメーター

type

"Primary" | "FirstPage" | "EvenPages"

返されるフッターの型。 この値には、 primaryfirstPageevenPages のいずれかを指定する必要があります。

返品

注釈

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

返されるヘッダーの型。 この値には、 primaryfirstPageevenPages のいずれかを指定する必要があります。

返品

注釈

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(type)

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

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

パラメーター

type

"Primary" | "FirstPage" | "EvenPages"

返されるヘッダーの型。 この値には、 primaryfirstPageevenPages のいずれかを指定する必要があります。

返品

注釈

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()

次のセクションを取得します。 このセクションが最後の場合、このメソッドは isNullObject プロパティが true に設定されたオブジェクトを返します。 詳細については、「 *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

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

返品

void

set(properties)

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

set(properties: Word.Section): void;

パラメーター

properties
Word.Section

返品

void

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、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;

返品