Skip to content

Commit 706a2d6

Browse files
[Word] (ShapeFill) Add snippet for clear and set (#1022)
1 parent 34f77c8 commit 706a2d6

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ script:
1414
document.getElementById("get-first-geometric-shape").addEventListener("click", () => tryCatch(getFirstGeometricShape));
1515
document.getElementById("get-first-heptagon").addEventListener("click", () => tryCatch(getFirstHeptagon));
1616
document.getElementById("get-first-moon-fill").addEventListener("click", () => tryCatch(getFirstMoonColorFill));
17+
document.getElementById("clear-first-moon-fill").addEventListener("click", () => tryCatch(clearFirstMoonColorFill));
18+
document.getElementById("set-first-moon-fill").addEventListener("click", () => tryCatch(setFirstMoonColorFill));
1719
1820
async function insertGeometricShape_Heptagon() {
1921
await Word.run(async (context) => {
@@ -136,6 +138,56 @@ script:
136138
});
137139
}
138140
141+
async function clearFirstMoonColorFill() {
142+
await Word.run(async (context) => {
143+
// Clears the color fill properties of the first moon found in the document body.
144+
const moon: Word.Shape = context.document.body.shapes
145+
.getByGeometricTypes([Word.GeometricShapeType.moon])
146+
.getFirstOrNullObject();
147+
moon.load("fill");
148+
await context.sync();
149+
150+
if (moon.isNullObject) {
151+
console.log("No moons found in the document body.");
152+
return;
153+
}
154+
155+
const moonFill: Word.ShapeFill = moon.fill;
156+
console.log("Current fill properties of the first moon found in the document body:", moonFill);
157+
158+
moonFill.clear();
159+
moonFill.load();
160+
await context.sync();
161+
162+
console.log("Cleared the color fill properties of the first moon found in the document body:", moonFill);
163+
});
164+
}
165+
166+
async function setFirstMoonColorFill() {
167+
await Word.run(async (context) => {
168+
// Sets color fill properties of the first moon found in the document body.
169+
const moon: Word.Shape = context.document.body.shapes
170+
.getByGeometricTypes([Word.GeometricShapeType.moon])
171+
.getFirstOrNullObject();
172+
moon.load("fill");
173+
await context.sync();
174+
175+
if (moon.isNullObject) {
176+
console.log("No moons found in the document body.");
177+
return;
178+
}
179+
180+
const moonFill: Word.ShapeFill = moon.fill;
181+
console.log("Current fill properties of the first moon found in the document body:", moonFill);
182+
183+
moonFill.setSolidColor("green");
184+
moonFill.load();
185+
await context.sync();
186+
187+
console.log("Updated color fill properties of the first moon found in the document body:", moonFill);
188+
});
189+
}
190+
139191
// Default helper for invoking an action and handling errors.
140192
async function tryCatch(callback) {
141193
try {
@@ -171,8 +223,15 @@ template:
171223
<button id="get-first-heptagon" class="ms-Button">
172224
<span class="ms-Button-label">Get first heptagon</span>
173225
</button>
226+
<h4>Work with color fill properties of the first moon</h4>
174227
<button id="get-first-moon-fill" class="ms-Button">
175-
<span class="ms-Button-label">Get color fill of first moon</span>
228+
<span class="ms-Button-label">Get color fill</span>
229+
</button>
230+
<button id="clear-first-moon-fill" class="ms-Button">
231+
<span class="ms-Button-label">Clear color fill properties</span>
232+
</button>
233+
<button id="set-first-moon-fill" class="ms-Button">
234+
<span class="ms-Button-label">Set color fill properties</span>
176235
</button>
177236
</section>
178237
language: html
93 Bytes
Binary file not shown.

snippet-extractor-output/snippets.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28252,6 +28252,62 @@ Word.ShapeFill:class:
2825228252
console.log(`\tTransparency: ${moonFill.transparency}`);
2825328253
console.log(`\tFill type: ${moonFillType}`);
2825428254
});
28255+
Word.ShapeFill#clear:member(1):
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+
// Sets 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+
console.log("Current fill properties of the first moon found in the document body:", moonFill);
28276+
28277+
moonFill.setSolidColor("green");
28278+
moonFill.load();
28279+
await context.sync();
28280+
28281+
console.log("Updated color fill properties of the first moon found in the document body:", moonFill);
28282+
});
28283+
Word.ShapeFill#setSolidColor:member(1):
28284+
- >-
28285+
// Link to full sample:
28286+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/45-shapes/manage-geometric-shapes.yaml
28287+
28288+
28289+
await Word.run(async (context) => {
28290+
// Sets color fill properties of the first moon found in the document body.
28291+
const moon: Word.Shape = context.document.body.shapes
28292+
.getByGeometricTypes([Word.GeometricShapeType.moon])
28293+
.getFirstOrNullObject();
28294+
moon.load("fill");
28295+
await context.sync();
28296+
28297+
if (moon.isNullObject) {
28298+
console.log("No moons found in the document body.");
28299+
return;
28300+
}
28301+
28302+
const moonFill: Word.ShapeFill = moon.fill;
28303+
console.log("Current fill properties of the first moon found in the document body:", moonFill);
28304+
28305+
moonFill.setSolidColor("green");
28306+
moonFill.load();
28307+
await context.sync();
28308+
28309+
console.log("Updated color fill properties of the first moon found in the document body:", moonFill);
28310+
});
2825528311
Word.ShapeFillType:enum:
2825628312
- >-
2825728313
// Link to full sample:

0 commit comments

Comments
 (0)