Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Rick-Kirkham/fb2cce670dec338486464a4ddb2702f1 to your computer and use it in GitHub Desktop.
Save Rick-Kirkham/fb2cce670dec338486464a4ddb2702f1 to your computer and use it in GitHub Desktop.
Executes a basic Word API call using TypeScript. - Shared with Script Lab
name: Repro ContentControls.getByTag bug
description: Executes a basic Word API call using TypeScript.
author: Rick-Kirkham
host: WORD
api_set: {}
script:
content: |-
$("#run").click(() => tryCatch(run));
async function run() {
// Gets the current selection and changes the font color to red.
await Word.run(async (context) => {
const contentControls = context.document.contentControls.getByTag('Inner').load();
await context.sync();
console.log(contentControls.items.length);
contentControls.items.forEach(contentControl => {
contentControl.cannotDelete = false;
contentControl.cannotEdit = false;
contentControl.delete(false);
});
await context.sync();
// console.log(`The selected text was "${range.text}".`);
});
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
}
catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
language: typescript
template:
content: |-
<p class="ms-font-m">Executes a simple code snippet. Make sure to select text before clicking "Run code".</p>
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run code</span>
</button>
language: html
style:
content: |-
body {
margin: 0;
padding: 10px;
}
/* Button customization, including overwriting some Fabric defaults */
.ms-Button, .ms-Button:focus {
background: #2b579a;
border: #2b579a;
}
.ms-Button > .ms-Button-label,
.ms-Button:focus > .ms-Button-label,
.ms-Button:hover > .ms-Button-label {
color: white;
}
.ms-Button:hover, .ms-Button:active {
background: #204072;
}
.ms-Button.is-disabled, .ms-Button:disabled {
background-color: #f4f4f4;
border-color: #f4f4f4;
}
.ms-Button.is-disabled .ms-Button-label,
.ms-Button:disabled .ms-Button-label {
color: #a6a6a6;
}
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.d.ts
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css
core-js@2.4.1/client/core.min.js
@types/core-js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts
jquery@3.1.1
@types/jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment