Skip to content

Commit 34f77c8

Browse files
[Word] (ShapeFill) Add snippet (#1021)
* [Word] (ShapeFill) Add snippet * Fix typo
1 parent 0679d3a commit 34f77c8

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

samples/word/45-shapes/manage-geometric-shapes.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ script:
1313
document.getElementById("get-moons").addEventListener("click", () => tryCatch(getMoonGeometricShapes));
1414
document.getElementById("get-first-geometric-shape").addEventListener("click", () => tryCatch(getFirstGeometricShape));
1515
document.getElementById("get-first-heptagon").addEventListener("click", () => tryCatch(getFirstHeptagon));
16+
document.getElementById("get-first-moon-fill").addEventListener("click", () => tryCatch(getFirstMoonColorFill));
1617
1718
async function insertGeometricShape_Heptagon() {
1819
await Word.run(async (context) => {
@@ -41,7 +42,7 @@ script:
4142
selection.insertGeometricShape(Word.GeometricShapeType.moon, shapeOptions);
4243
await context.sync();
4344
44-
console.log("Inserted a heptagon.");
45+
console.log("Inserted a moon.");
4546
});
4647
}
4748
@@ -110,6 +111,31 @@ script:
110111
});
111112
}
112113
114+
async function getFirstMoonColorFill() {
115+
await Word.run(async (context) => {
116+
// Gets the color fill properties of the first moon found in the document body.
117+
const moon: Word.Shape = context.document.body.shapes
118+
.getByGeometricTypes([Word.GeometricShapeType.moon])
119+
.getFirstOrNullObject();
120+
moon.load("fill");
121+
await context.sync();
122+
123+
if (moon.isNullObject) {
124+
console.log("No moons found in the document body.");
125+
return;
126+
}
127+
128+
const moonFill: Word.ShapeFill = moon.fill;
129+
const moonFillType = moonFill.type as Word.ShapeFillType;
130+
131+
console.log("Color fill properties of the first moon found in the document body:");
132+
console.log(`\tForeground color: ${moonFill.foregroundColor}`);
133+
console.log(`\tBackground color: ${moonFill.backgroundColor}`);
134+
console.log(`\tTransparency: ${moonFill.transparency}`);
135+
console.log(`\tFill type: ${moonFillType}`);
136+
});
137+
}
138+
113139
// Default helper for invoking an action and handling errors.
114140
async function tryCatch(callback) {
115141
try {
@@ -145,6 +171,9 @@ template:
145171
<button id="get-first-heptagon" class="ms-Button">
146172
<span class="ms-Button-label">Get first heptagon</span>
147173
</button>
174+
<button id="get-first-moon-fill" class="ms-Button">
175+
<span class="ms-Button-label">Get color fill of first moon</span>
176+
</button>
148177
</section>
149178
language: html
150179
style:
153 Bytes
Binary file not shown.

snippet-extractor-output/snippets.yaml

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27483,7 +27483,7 @@ Word.Range#insertGeometricShape:member(1):
2748327483
selection.insertGeometricShape(Word.GeometricShapeType.moon, shapeOptions);
2748427484
await context.sync();
2748527485

27486-
console.log("Inserted a heptagon.");
27486+
console.log("Inserted a moon.");
2748727487
});
2748827488
Word.Range#insertTextBox:member(1):
2748927489
- >-
@@ -27986,6 +27986,34 @@ Word.Shape#body:member:
2798627986

2798727987
console.log("New content control properties:", newControl);
2798827988
});
27989+
Word.Shape#fill:member:
27990+
- >-
27991+
// Link to full sample:
27992+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-geometric-shapes.yaml
27993+
27994+
27995+
await Word.run(async (context) => {
27996+
// Gets the color fill properties of the first moon found in the document body.
27997+
const moon: Word.Shape = context.document.body.shapes
27998+
.getByGeometricTypes([Word.GeometricShapeType.moon])
27999+
.getFirstOrNullObject();
28000+
moon.load("fill");
28001+
await context.sync();
28002+
28003+
if (moon.isNullObject) {
28004+
console.log("No moons found in the document body.");
28005+
return;
28006+
}
28007+
28008+
const moonFill: Word.ShapeFill = moon.fill;
28009+
const moonFillType = moonFill.type as Word.ShapeFillType;
28010+
28011+
console.log("Color fill properties of the first moon found in the document body:");
28012+
console.log(`\tForeground color: ${moonFill.foregroundColor}`);
28013+
console.log(`\tBackground color: ${moonFill.backgroundColor}`);
28014+
console.log(`\tTransparency: ${moonFill.transparency}`);
28015+
console.log(`\tFill type: ${moonFillType}`);
28016+
});
2798928017
Word.Shape#geometricShapeType:member:
2799028018
- >-
2799128019
// Link to full sample:
@@ -28196,6 +28224,62 @@ Word.ShapeCollection#getFirstOrNullObject:member(1):
2819628224
: `Text in first text box: ${shape.body.text}`
2819728225
);
2819828226
});
28227+
Word.ShapeFill:class:
28228+
- >-
28229+
// Link to full sample:
28230+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-geometric-shapes.yaml
28231+
28232+
28233+
await Word.run(async (context) => {
28234+
// Gets the color fill properties of the first moon found in the document body.
28235+
const moon: Word.Shape = context.document.body.shapes
28236+
.getByGeometricTypes([Word.GeometricShapeType.moon])
28237+
.getFirstOrNullObject();
28238+
moon.load("fill");
28239+
await context.sync();
28240+
28241+
if (moon.isNullObject) {
28242+
console.log("No moons found in the document body.");
28243+
return;
28244+
}
28245+
28246+
const moonFill: Word.ShapeFill = moon.fill;
28247+
const moonFillType = moonFill.type as Word.ShapeFillType;
28248+
28249+
console.log("Color fill properties of the first moon found in the document body:");
28250+
console.log(`\tForeground color: ${moonFill.foregroundColor}`);
28251+
console.log(`\tBackground color: ${moonFill.backgroundColor}`);
28252+
console.log(`\tTransparency: ${moonFill.transparency}`);
28253+
console.log(`\tFill type: ${moonFillType}`);
28254+
});
28255+
Word.ShapeFillType:enum:
28256+
- >-
28257+
// Link to full sample:
28258+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-geometric-shapes.yaml
28259+
28260+
28261+
await Word.run(async (context) => {
28262+
// Gets the color fill properties of the first moon found in the document body.
28263+
const moon: Word.Shape = context.document.body.shapes
28264+
.getByGeometricTypes([Word.GeometricShapeType.moon])
28265+
.getFirstOrNullObject();
28266+
moon.load("fill");
28267+
await context.sync();
28268+
28269+
if (moon.isNullObject) {
28270+
console.log("No moons found in the document body.");
28271+
return;
28272+
}
28273+
28274+
const moonFill: Word.ShapeFill = moon.fill;
28275+
const moonFillType = moonFill.type as Word.ShapeFillType;
28276+
28277+
console.log("Color fill properties of the first moon found in the document body:");
28278+
console.log(`\tForeground color: ${moonFill.foregroundColor}`);
28279+
console.log(`\tBackground color: ${moonFill.backgroundColor}`);
28280+
console.log(`\tTransparency: ${moonFill.transparency}`);
28281+
console.log(`\tFill type: ${moonFillType}`);
28282+
});
2819928283
Word.ShapeTextOrientation:enum:
2820028284
- >-
2820128285
// Link to full sample:

0 commit comments

Comments
 (0)