@@ -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
0 commit comments