Skip to content

Instantly share code, notes, and snippets.

@JuaneloJuanelo
Last active February 12, 2018 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuaneloJuanelo/c8dc454e053d264f284054362195eca4 to your computer and use it in GitHub Desktop.
Save JuaneloJuanelo/c8dc454e053d264f284054362195eca4 to your computer and use it in GitHub Desktop.
Shared with Script Lab
name: Inserting Blank after CC
description: ''
author: JuaneloJuanelo
host: WORD
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Word.run(async (context) => {
// i'll insert the space before inserting the content control
//will get the range to set the curos positioning at the end.
let range = context.document.getSelection().insertText(" ", "end");
//we add the cc on the selection
let myCC = context.document.getSelection().insertContentControl();
//change any property you need for the text and the cc
let text = myCC.insertText("controlText", "replace");
text.font.color = "red";
myCC.title = "my Title";
range.select("end");
await context.sync();
});
}
/** 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: |
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
language: html
style:
content: |
/* Your style goes here */
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