Word.Style class

Word 文書のスタイルを表します。

Extends

注釈

[ API セット: WordApi 1.3 ]

プロパティ

baseStyle

別のスタイルの基本書式として使用する既存のスタイルの名前を指定します。

borders

指定したスタイルのすべての罫線を表す BorderCollection オブジェクトを指定します。

builtIn

指定したスタイルが組み込みスタイルであるかどうかを取得します。

context

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

description

指定したスタイルの説明を取得します。

font

指定したスタイルの文字書式を表すフォント オブジェクトを取得します。

inUse

指定したスタイルが、ドキュメント内で変更または適用された組み込みスタイルであるか、ドキュメント内に作成された新しいスタイルであるかを取得します。

linked

スタイルが、段落と文字の書式設定の両方に使用できるリンクされたスタイルであるかどうかを取得します。

listTemplate

指定した Style オブジェクトのリストの書式設定を表す ListTemplate オブジェクトを取得します。

nameLocal

ユーザーの言語でスタイルの名前を取得します。

nextParagraphStyle

指定したスタイルで書式設定された段落の後に挿入される新しい段落に自動的に適用されるスタイルの名前を指定します。

paragraphFormat

指定したスタイルの段落設定を表す ParagraphFormat オブジェクトを取得します。

priority

優先順位を指定します。

quickStyle

スタイルが使用可能なクイック スタイルに対応するかどうかを指定します。

shading

指定したスタイルの網かけを表す Shading オブジェクトを取得します。 リスト スタイルには適用されません。

tableStyle

テーブルに適用できる Style プロパティを表す TableStyle オブジェクトを取得します。

type

スタイルの種類を取得します。

unhideWhenUsed

指定したスタイルを文書で使用した後、[スタイル] および [スタイル] 作業ウィンドウで推奨スタイルとして表示するかどうかを指定します。

visibility

[スタイル] ギャラリーと [スタイル] 作業ウィンドウで、指定したスタイルを推奨スタイルとして表示するかどうかを指定します。

メソッド

delete()

スタイルを削除します。

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

track()

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

untrack()

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

プロパティの詳細

baseStyle

別のスタイルの基本書式として使用する既存のスタイルの名前を指定します。

baseStyle: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.5 ]

注: baseStyle を設定する機能は、WordApi 1.6 で導入されました。

borders

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

指定したスタイルのすべての罫線を表す BorderCollection オブジェクトを指定します。

readonly borders: Word.BorderCollection;

プロパティ値

注釈

[ API セット: WordApi BETA (プレビューのみ) ]

builtIn

指定したスタイルが組み込みスタイルであるかどうかを取得します。

readonly builtIn: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.5 ]

context

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

context: RequestContext;

プロパティ値

description

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

指定したスタイルの説明を取得します。

readonly description: string;

プロパティ値

string

注釈

[ API セット: WordApi BETA (プレビューのみ) ]

font

指定したスタイルの文字書式を表すフォント オブジェクトを取得します。

readonly font: Word.Font;

プロパティ値

注釈

[ API セット: WordApi 1.5 ]

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

// Updates font properties (e.g., color, size) of the specified style.
await Word.run(async (context) => {
  const styleName = $("#style-name").val() as string;
  if (styleName == "") {
    console.warn("Enter a style name to update font properties.");
    return;
  }

  const style: Word.Style = context.document.getStyles().getByNameOrNullObject(styleName);
  style.load();
  await context.sync();

  if (style.isNullObject) {
    console.warn(`There's no existing style with the name '${styleName}'.`);
  } else {
    const font: Word.Font = style.font;
    font.color = "#FF0000";
    font.size = 20;
    console.log(`Successfully updated font properties of the '${styleName}' style.`);
  }
});

inUse

指定したスタイルが、ドキュメント内で変更または適用された組み込みスタイルであるか、ドキュメント内に作成された新しいスタイルであるかを取得します。

readonly inUse: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.5 ]

linked

スタイルが、段落と文字の書式設定の両方に使用できるリンクされたスタイルであるかどうかを取得します。

readonly linked: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.5 ]

listTemplate

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

指定した Style オブジェクトのリストの書式設定を表す ListTemplate オブジェクトを取得します。

readonly listTemplate: Word.ListTemplate;

プロパティ値

注釈

[ API セット: WordApi BETA (プレビューのみ) ]

nameLocal

ユーザーの言語でスタイルの名前を取得します。

readonly nameLocal: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.5 ]

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

// Applies the specified style to a paragraph.
await Word.run(async (context) => {
  const styleName = $("#style-name-to-use").val() as string;
  if (styleName == "") {
    console.warn("Enter a style name to apply.");
    return;
  }

  const style: Word.Style = context.document.getStyles().getByNameOrNullObject(styleName);
  style.load();
  await context.sync();

  if (style.isNullObject) {
    console.warn(`There's no existing style with the name '${styleName}'.`);
  } else if (style.type != Word.StyleType.paragraph) {
    console.log(`The '${styleName}' style isn't a paragraph style.`);
  } else {
    const body: Word.Body = context.document.body;
    body.clear();
    body.insertParagraph(
      "Do you want to create a solution that extends the functionality of Word? You can use the Office Add-ins platform to extend Word clients running on the web, on a Windows desktop, or on a Mac.",
      "Start"
    );
    const paragraph: Word.Paragraph = body.paragraphs.getFirst();
    paragraph.style = style.nameLocal;
    console.log(`'${styleName}' style applied to first paragraph.`);
  }
});

nextParagraphStyle

指定したスタイルで書式設定された段落の後に挿入される新しい段落に自動的に適用されるスタイルの名前を指定します。

nextParagraphStyle: string;

プロパティ値

string

注釈

[ API セット: WordApi 1.5 ]

注: nextParagraphStyle を設定する機能は、WordApi 1.6 で導入されました。

paragraphFormat

指定したスタイルの段落設定を表す ParagraphFormat オブジェクトを取得します。

readonly paragraphFormat: Word.ParagraphFormat;

プロパティ値

注釈

[ API セット: WordApi 1.5 ]

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

// Sets certain aspects of the specified style's paragraph format e.g., the left indent size and the alignment.
await Word.run(async (context) => {
  const styleName = $("#style-name").val() as string;
  if (styleName == "") {
    console.warn("Enter a style name to update its paragraph format.");
    return;
  }

  const style: Word.Style = context.document.getStyles().getByNameOrNullObject(styleName);
  style.load();
  await context.sync();

  if (style.isNullObject) {
    console.warn(`There's no existing style with the name '${styleName}'.`);
  } else {
    style.paragraphFormat.leftIndent = 30;
    style.paragraphFormat.alignment = Word.Alignment.centered;
    console.log(`Successfully the paragraph format of the '${styleName}' style.`);
  }
});

priority

優先順位を指定します。

priority: number;

プロパティ値

number

注釈

[ API セット: WordApi 1.5 ]

quickStyle

スタイルが使用可能なクイック スタイルに対応するかどうかを指定します。

quickStyle: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.5 ]

shading

指定したスタイルの網かけを表す Shading オブジェクトを取得します。 リスト スタイルには適用されません。

readonly shading: Word.Shading;

プロパティ値

注釈

[ API セット: WordApi 1.6 ]

tableStyle

テーブルに適用できる Style プロパティを表す TableStyle オブジェクトを取得します。

readonly tableStyle: Word.TableStyle;

プロパティ値

注釈

[ API セット: WordApi 1.6 ]

type

スタイルの種類を取得します。

readonly type: Word.StyleType | "Character" | "List" | "Paragraph" | "Table";

プロパティ値

Word.StyleType | "Character" | "List" | "Paragraph" | "Table"

注釈

[ API セット: WordApi 1.5 ]

unhideWhenUsed

指定したスタイルを文書で使用した後、[スタイル] および [スタイル] 作業ウィンドウで推奨スタイルとして表示するかどうかを指定します。

unhideWhenUsed: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.5 ]

visibility

[スタイル] ギャラリーと [スタイル] 作業ウィンドウで、指定したスタイルを推奨スタイルとして表示するかどうかを指定します。

visibility: boolean;

プロパティ値

boolean

注釈

[ API セット: WordApi 1.5 ]

メソッドの詳細

delete()

スタイルを削除します。

delete(): void;

戻り値

void

注釈

[ API セット: WordApi 1.5 ]

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

// Deletes the custom style.
await Word.run(async (context) => {
  const styleName = $("#style-name-to-delete").val() as string;
  if (styleName == "") {
    console.warn("Enter a style name to delete.");
    return;
  }

  const style: Word.Style = context.document.getStyles().getByNameOrNullObject(styleName);
  style.load();
  await context.sync();

  if (style.isNullObject) {
    console.warn(`There's no existing style with the name '${styleName}'.`);
  } else {
    style.delete();
    console.log(`Successfully deleted custom style '${styleName}'.`);
  }
});

load(options)

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

load(options?: Word.Interfaces.StyleLoadOptions): Word.Style;

パラメーター

options
Word.Interfaces.StyleLoadOptions

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

戻り値

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

戻り値

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

戻り値

set(properties, options)

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

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

パラメーター

properties
Word.Interfaces.StyleUpdateData

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

options
OfficeExtension.UpdateOptions

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

戻り値

void

set(properties)

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

set(properties: Word.Style): void;

パラメーター

properties
Word.Style

戻り値

void

toJSON()

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

toJSON(): Word.Interfaces.StyleData;

戻り値

track()

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

track(): Word.Style;

戻り値

untrack()

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

untrack(): Word.Style;

戻り値