Word.ShapeFill class

Word の塗りつぶしの書式を表します。Shape オブジェクト。

Extends

注釈

API セット: WordApiDesktop 1.2

使用元

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-geometric-shapes.yaml

await Word.run(async (context) => {
  // Gets the color fill properties of the first moon found in the document body.
  const moon: Word.Shape = context.document.body.shapes
    .getByGeometricTypes([Word.GeometricShapeType.moon])
    .getFirstOrNullObject();
  moon.load("fill");
  await context.sync();

  if (moon.isNullObject) {
    console.log("No moons found in the document body.");
    return;
  }

  const moonFill: Word.ShapeFill = moon.fill;
  const moonFillType = moonFill.type as Word.ShapeFillType;

  console.log("Color fill properties of the first moon found in the document body:");
  console.log(`\tForeground color: ${moonFill.foregroundColor}`);
  console.log(`\tBackground color: ${moonFill.backgroundColor}`);
  console.log(`\tTransparency: ${moonFill.transparency}`);
  console.log(`\tFill type: ${moonFillType}`);
});

プロパティ

backgroundColor

図形の塗りつぶしの背景色を指定します。 値は '#RRGGBB' 形式または色名で指定できます。

context

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

foregroundColor

図形の塗りつぶしの前景色を指定します。 値は '#RRGGBB' 形式または色名で指定できます。

transparency

塗りつぶしの透明度の割合を、0.0 (不透明) から 1.0 (クリア) までの値で指定します。 図形の種類が透明度をサポートしていない場合や、グラデーションの塗りつぶしの種類など、図形の塗りつぶしの透明度に一貫性がない場合は null を返します。

type

図形の塗りつぶしの種類を返します。 詳細は「Word.ShapeFillType」をご覧ください。

メソッド

clear()

この図形の塗りつぶしの書式設定をクリアして Word.ShapeFillType.noFillに設定します。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

set(properties, options)

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

set(properties)

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

setSolidColor(color)

図形の塗りつぶしの書式設定を均一な色に設定します。 これにより、塗りつぶしの種類が Word.ShapeFillType.solid に変わります。

toJSON()

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

track()

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

untrack()

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

プロパティの詳細

backgroundColor

図形の塗りつぶしの背景色を指定します。 値は '#RRGGBB' 形式または色名で指定できます。

backgroundColor: string;

プロパティ値

string

注釈

API セット: WordApiDesktop 1.2

context

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

context: RequestContext;

プロパティ値

foregroundColor

図形の塗りつぶしの前景色を指定します。 値は '#RRGGBB' 形式または色名で指定できます。

foregroundColor: string;

プロパティ値

string

注釈

API セット: WordApiDesktop 1.2

transparency

塗りつぶしの透明度の割合を、0.0 (不透明) から 1.0 (クリア) までの値で指定します。 図形の種類が透明度をサポートしていない場合や、グラデーションの塗りつぶしの種類など、図形の塗りつぶしの透明度に一貫性がない場合は null を返します。

transparency: number;

プロパティ値

number

注釈

API セット: WordApiDesktop 1.2

type

図形の塗りつぶしの種類を返します。 詳細は「Word.ShapeFillType」をご覧ください。

readonly type: Word.ShapeFillType | "NoFill" | "Solid" | "Gradient" | "Pattern" | "Picture" | "Texture" | "Mixed";

プロパティ値

Word.ShapeFillType | "NoFill" | "Solid" | "Gradient" | "Pattern" | "Picture" | "Texture" | "Mixed"

注釈

API セット: WordApiDesktop 1.2

メソッドの詳細

clear()

この図形の塗りつぶしの書式設定をクリアして Word.ShapeFillType.noFillに設定します。

clear(): void;

返品

void

注釈

API セット: WordApiDesktop 1.2

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-geometric-shapes.yaml

await Word.run(async (context) => {
  // Sets color fill properties of the first moon found in the document body.
  const moon: Word.Shape = context.document.body.shapes
    .getByGeometricTypes([Word.GeometricShapeType.moon])
    .getFirstOrNullObject();
  moon.load("fill");
  await context.sync();

  if (moon.isNullObject) {
    console.log("No moons found in the document body.");
    return;
  }

  const moonFill: Word.ShapeFill = moon.fill;
  console.log("Current fill properties of the first moon found in the document body:", moonFill);

  moonFill.setSolidColor("green");
  moonFill.load();
  await context.sync();

  console.log("Updated color fill properties of the first moon found in the document body:", moonFill);
});

load(options)

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

load(options?: Word.Interfaces.ShapeFillLoadOptions): Word.ShapeFill;

パラメーター

options
Word.Interfaces.ShapeFillLoadOptions

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

返品

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

返品

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

返品

set(properties, options)

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

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

パラメーター

properties
Word.Interfaces.ShapeFillUpdateData

メソッドが呼び出されたオブジェクトのプロパティと同型構造のプロパティを持つ JavaScript オブジェクト。

options
OfficeExtension.UpdateOptions

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

返品

void

set(properties)

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

set(properties: Word.ShapeFill): void;

パラメーター

properties
Word.ShapeFill

返品

void

setSolidColor(color)

図形の塗りつぶしの書式設定を均一な色に設定します。 これにより、塗りつぶしの種類が Word.ShapeFillType.solid に変わります。

setSolidColor(color: string): void;

パラメーター

color

string

塗りつぶしの前景色を表す文字列。 値は '#RRGGBB' 形式または色名で指定できます。

返品

void

注釈

API セット: WordApiDesktop 1.2

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-geometric-shapes.yaml

await Word.run(async (context) => {
  // Sets color fill properties of the first moon found in the document body.
  const moon: Word.Shape = context.document.body.shapes
    .getByGeometricTypes([Word.GeometricShapeType.moon])
    .getFirstOrNullObject();
  moon.load("fill");
  await context.sync();

  if (moon.isNullObject) {
    console.log("No moons found in the document body.");
    return;
  }

  const moonFill: Word.ShapeFill = moon.fill;
  console.log("Current fill properties of the first moon found in the document body:", moonFill);

  moonFill.setSolidColor("green");
  moonFill.load();
  await context.sync();

  console.log("Updated color fill properties of the first moon found in the document body:", moonFill);
});

toJSON()

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

toJSON(): Word.Interfaces.ShapeFillData;

返品

track()

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

track(): Word.ShapeFill;

返品

untrack()

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

untrack(): Word.ShapeFill;

返品