PowerPoint.ShapeFill class
図形オブジェクトの塗りつぶしの書式設定を表します。
- Extends
注釈
使用元
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
// Changes the transparency of every geometric shape in the slide.
await PowerPoint.run(async (context) => {
// Get the type of shape for every shape in the collection.
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
shapes.load("type");
await context.sync();
// Change the shape transparency to be halfway transparent.
shapes.items.forEach((shape) => {
if (shape.type === PowerPoint.ShapeType.geometricShape) {
shape.fill.transparency = 0.5;
}
});
await context.sync();
});
プロパティ
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
| foreground |
図形の塗りつぶしの前景色を HTML カラー形式で、#RRGGBB 形式 (例: "FFA500") または名前付き HTML 色 (例: "オレンジ") で表します。 |
| transparency | 塗りつぶしの透明度の割合を、0.0 (不透明) から 1.0 (クリア) までの値で指定します。 図形の種類が透明度をサポートしていない場合、またはグラデーション塗りつぶしの種類など、図形の塗りつぶしに一貫性のない透明度がある場合は |
| type | 図形の塗りつぶしの種類を返します。 詳細については 、PowerPoint.ShapeFillType を参照してください。 |
メソッド
| clear() | この図形の塗りつぶしの書式設定をクリアします。 |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| set |
図形の塗りつぶしの書式設定を画像に設定します。 これにより、塗りつぶしの種類が |
| set |
図形の塗りつぶしの書式設定を均一な色に設定します。 これにより、塗りつぶしの種類が |
| toJSON() | API オブジェクトが |
プロパティの詳細
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
foregroundColor
図形の塗りつぶしの前景色を HTML カラー形式で、#RRGGBB 形式 (例: "FFA500") または名前付き HTML 色 (例: "オレンジ") で表します。
foregroundColor: string;
プロパティ値
string
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Creates random shapes on the selected slide.
await PowerPoint.run(async (context) => {
let finalTable = "";
const currentSlide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
const maxNewShapeWidth = 200;
const maxNewShapeHeight = 200;
const minNewShapeWidth = 50;
const minNewShapeHeight = 50;
for (let i = 0; i < 20; i++) {
const rectangle: PowerPoint.Shape = currentSlide.shapes.addGeometricShape(
PowerPoint.GeometricShapeType.rectangle,
);
rectangle.height = getRandomBetween(minNewShapeWidth, maxNewShapeWidth);
rectangle.width = getRandomBetween(minNewShapeHeight, maxNewShapeHeight);
rectangle.left = getRandomBetween(0, slideWidth - rectangle.width);
rectangle.top = getRandomBetween(0, slideHeight - rectangle.height);
rectangle.fill.foregroundColor = generateRandomHexColor();
}
finalTable += "Done<br>";
const outputSpan = document.getElementById("outputSpan");
outputSpan.innerHTML = "";
outputSpan.innerHTML += finalTable;
});
transparency
塗りつぶしの透明度の割合を、0.0 (不透明) から 1.0 (クリア) までの値で指定します。 図形の種類が透明度をサポートしていない場合、またはグラデーション塗りつぶしの種類など、図形の塗りつぶしに一貫性のない透明度がある場合は null を返します。
transparency: number;
プロパティ値
number
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shapes-by-type.yaml
// Changes the transparency of every geometric shape in the slide.
await PowerPoint.run(async (context) => {
// Get the type of shape for every shape in the collection.
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
shapes.load("type");
await context.sync();
// Change the shape transparency to be halfway transparent.
shapes.items.forEach((shape) => {
if (shape.type === PowerPoint.ShapeType.geometricShape) {
shape.fill.transparency = 0.5;
}
});
await context.sync();
});
type
図形の塗りつぶしの種類を返します。 詳細については 、PowerPoint.ShapeFillType を参照してください。
readonly type: PowerPoint.ShapeFillType | "NoFill" | "Solid" | "Gradient" | "Pattern" | "PictureAndTexture" | "SlideBackground";
プロパティ値
PowerPoint.ShapeFillType | "NoFill" | "Solid" | "Gradient" | "Pattern" | "PictureAndTexture" | "SlideBackground"
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Changes the selected shapes fill color to red.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items/fill/type");
await context.sync();
shapes.items.map((shape) => {
const shapeFillType = shape.fill.type as PowerPoint.ShapeFillType;
console.log(`Shape ID ${shape.id} original fill type: ${shapeFillType}`);
shape.fill.setSolidColor("red");
});
await context.sync();
});
メソッドの詳細
clear()
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(options?: PowerPoint.Interfaces.ShapeFillLoadOptions): PowerPoint.ShapeFill;
パラメーター
読み込むオブジェクトのプロパティのオプションを指定します。
返品
load(propertyNames)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNames?: string | string[]): PowerPoint.ShapeFill;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。
返品
load(propertyNamesAndPaths)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): PowerPoint.ShapeFill;
パラメーター
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。
返品
setImage(base64EncodedImage)
図形の塗りつぶしの書式設定を画像に設定します。 これにより、塗りつぶしの種類が PictureAndTexture に変わります。
setImage(base64EncodedImage: string): void;
パラメーター
- base64EncodedImage
-
string
画像データの Base64 エンコードである文字列。
返品
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
// Inserts an image with binding.
await PowerPoint.run(async (context) => {
const bindingId = (document.getElementById("temp-binding-id") as HTMLInputElement).value;
const slide = context.presentation.getSelectedSlides().getItemAt(0);
const myShape = slide.shapes.addGeometricShape(PowerPoint.GeometricShapeType.rectangle, {
top: 100,
left: 30,
width: 200,
height: 200
});
myShape.fill.setImage(flowerImage);
context.presentation.bindings.add(myShape, PowerPoint.BindingType.shape, bindingId);
await context.sync();
const bindingsDropdown = document.getElementById("bindings-dropdown") as HTMLSelectElement;
const option = new Option(`Binding ${bindingId}`, bindingId);
// When a binding ID already exists, the binding is updated to refer to the new shape
// so select the existing item rather than add a new one.
const foundIndex = findDropdownItem(bindingsDropdown, option.text);
if (foundIndex < 0) {
bindingsDropdown.add(option);
bindingsDropdown.selectedIndex = bindingsDropdown.options.length - 1;
} else {
bindingsDropdown.selectedIndex = foundIndex;
}
});
setSolidColor(color)
図形の塗りつぶしの書式設定を均一な色に設定します。 これにより、塗りつぶしの種類が Solid に変わります。
setSolidColor(color: string): void;
パラメーター
- color
-
string
HTML カラー形式で塗りつぶしの色を指定する文字列。形式は #RRGGBB (例: "FFA500")、または名前付き HTML カラー (例: "オレンジ") です。
返品
void
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml
// Changes the selected shapes fill color to red.
await PowerPoint.run(async (context) => {
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
shapes.load("items/fill/type");
await context.sync();
shapes.items.map((shape) => {
const shapeFillType = shape.fill.type as PowerPoint.ShapeFillType;
console.log(`Shape ID ${shape.id} original fill type: ${shapeFillType}`);
shape.fill.setSolidColor("red");
});
await context.sync();
});
toJSON()
API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の PowerPoint.ShapeFill オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( PowerPoint.Interfaces.ShapeFillData と型指定) を返します。
toJSON(): PowerPoint.Interfaces.ShapeFillData;