Word.Style class
Word ドキュメントのスタイルを表します。
- Extends
注釈
プロパティ
base |
別のスタイルの基本書式として使用する既存のスタイルの名前を指定します。 |
built |
指定したスタイルが組み込みスタイルであるかどうかを取得します。 |
context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
font | 指定したスタイルの文字書式を表すフォント オブジェクトを取得します。 |
in |
指定したスタイルが、ドキュメント内で変更または適用された組み込みスタイルであるか、ドキュメント内に作成された新しいスタイルであるかを取得します。 |
linked | スタイルが、段落と文字の書式設定の両方に使用できるリンクされたスタイルであるかどうかを取得します。 |
name |
ユーザーの言語でスタイルの名前を取得します。 |
next |
指定したスタイルで書式設定された段落の後に挿入される新しい段落に自動的に適用されるスタイルの名前を指定します。 |
paragraph |
指定したスタイルの段落設定を表す ParagraphFormat オブジェクトを取得します。 |
priority | 優先順位を指定します。 |
quick |
スタイルが使用可能なクイック スタイルに対応するかどうかを指定します。 |
type | スタイルの種類を取得します。 |
unhide |
指定したスタイルを文書で使用した後、[スタイル] および Microsoft Wordの [スタイル] 作業ウィンドウで推奨スタイルとして表示するかどうかを指定します。 |
visibility | [スタイル] ギャラリーと [スタイル] 作業ウィンドウで、指定したスタイルを推奨スタイルとして表示するかどうかを指定します。 |
メソッド
delete() | スタイルを削除します。 |
load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
set(properties, options) | オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクトまたは同じ型の別の API オブジェクトを渡すことができます。 |
set(properties) | 既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。 |
toJSON() | API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript |
track() | ドキュメントの環境変更に基づいて自動的に調整する目的でオブジェクトを追跡します。 この呼び出しは、context.trackedObjects.add(thisObject)の短縮形です。 このオブジェクトを呼び出しで |
untrack() | 前に追跡されていた場合、このオブジェクトに関連付けられているメモリを解放します。 この呼び出しは、context.trackedObjects.remove(thisObject)の短縮形です。 追跡対象オブジェクトが多いとホスト アプリケーションの動作が遅くなります。追加したオブジェクトが不要になったら、必ずそれを解放してください。 メモリ解放が有効になる前に を呼び出す |
プロパティの詳細
baseStyle
別のスタイルの基本書式として使用する既存のスタイルの名前を指定します。
baseStyle: string;
プロパティ値
string
注釈
注: 設定 baseStyle
機能は WordApi 1.6 で導入されました。
builtIn
指定したスタイルが組み込みスタイルであるかどうかを取得します。
readonly builtIn: boolean;
プロパティ値
boolean
注釈
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
font
指定したスタイルの文字書式を表すフォント オブジェクトを取得します。
readonly font: Word.Font;
プロパティ値
注釈
例
// 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 = 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 = style.font;
font.color = "#FF0000";
font.size = 20;
console.log(`Successfully updated font properties of the '${styleName}' style.`);
}
});
inUse
指定したスタイルが、ドキュメント内で変更または適用された組み込みスタイルであるか、ドキュメント内に作成された新しいスタイルであるかを取得します。
readonly inUse: boolean;
プロパティ値
boolean
注釈
linked
スタイルが、段落と文字の書式設定の両方に使用できるリンクされたスタイルであるかどうかを取得します。
readonly linked: boolean;
プロパティ値
boolean
注釈
nameLocal
ユーザーの言語でスタイルの名前を取得します。
readonly nameLocal: string;
プロパティ値
string
注釈
例
// 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 = 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 = context.document.body;
body.clear();
body.insertParagraph(
"Video provides a powerful way to help you prove your point. When you click Online Video, you can paste in the embed code for the video you want to add. You can also type a keyword to search online for the video that best fits your document.",
"Start"
);
const paragraph = body.paragraphs.getFirst();
paragraph.style = style.nameLocal;
console.log(`'${styleName}' style applied to first paragraph.`);
}
});
nextParagraphStyle
指定したスタイルで書式設定された段落の後に挿入される新しい段落に自動的に適用されるスタイルの名前を指定します。
nextParagraphStyle: string;
プロパティ値
string
注釈
注: 設定 nextParagraphStyle
機能は WordApi 1.6 で導入されました。
paragraphFormat
指定したスタイルの段落設定を表す ParagraphFormat オブジェクトを取得します。
readonly paragraphFormat: Word.ParagraphFormat;
プロパティ値
注釈
例
// 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 = 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
quickStyle
type
スタイルの種類を取得します。
readonly type: Word.StyleType | "Character" | "List" | "Paragraph" | "Table";
プロパティ値
Word.StyleType | "Character" | "List" | "Paragraph" | "Table"
注釈
unhideWhenUsed
指定したスタイルを文書で使用した後、[スタイル] および Microsoft Wordの [スタイル] 作業ウィンドウで推奨スタイルとして表示するかどうかを指定します。
unhideWhenUsed: boolean;
プロパティ値
boolean
注釈
visibility
[スタイル] ギャラリーと [スタイル] 作業ウィンドウで、指定したスタイルを推奨スタイルとして表示するかどうかを指定します。
visibility: boolean;
プロパティ値
boolean
注釈
メソッドの詳細
delete()
スタイルを削除します。
delete(): void;
戻り値
void
注釈
例
// 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 = 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 オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON()
メソッドを JSON.stringify()
オーバーライドします。 (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;
戻り値
Office Add-ins
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示