Created
August 19, 2023 05:27
-
-
Save lightman76/861bda6b4f31ba92993022a889b2ae41 to your computer and use it in GitHub Desktop.
Can delete an editable contentControl in Word Online
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Blank snippet | |
description: Creates a new snippet from a blank template. | |
host: WORD | |
api_set: {} | |
script: | |
content: | | |
var counter = 1; | |
Word['run'](async function (context) { | |
let doc = context.document; | |
let endOfBodyRange = doc.body.getRange(Word.RangeLocation.end); | |
let ccRange = endOfBodyRange.insertParagraph('', Word.InsertLocation.after); | |
let ccParagraph = ccRange.insertParagraph("", Word.InsertLocation.after); | |
await context.sync(); | |
//Find end after adding this and add another paragraph or else the insertion of the content control fails... | |
endOfBodyRange = doc.body.getRange(Word.RangeLocation.end); | |
var emptyParagraph = endOfBodyRange.insertParagraph("", Word.InsertLocation.after); | |
let cc = ccParagraph.insertContentControl(); | |
cc.cannotDelete = false; | |
cc.title = "Test Content Control"; | |
cc.tag = "EXAMPLE_TAG1"; | |
cc.cannotEdit = false; | |
try { | |
await context.sync(); | |
return fillContent(context, cc); | |
} catch (e) { | |
console.error("Failed to create content control during sync", e) | |
} | |
}); | |
async function fillContent(context, cc) { | |
console.log("fillContent start") | |
let entryPara = cc.insertParagraph("All work and no play makes Jack a dull boy.", Word.InsertLocation.end); | |
try { | |
await context.sync(); | |
console.log("fillContent completed") | |
} catch (e) { | |
console.error("fillContent: sync failed", e); | |
} | |
} | |
language: typescript | |
template: | |
content: | | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run</span> | |
</button> | |
language: html | |
style: | |
content: |- | |
section.samples { | |
margin-top: 20px; | |
} | |
section.samples .ms-Button, section.setup .ms-Button { | |
display: block; | |
margin-bottom: 5px; | |
margin-left: 20px; | |
min-width: 80px; | |
} | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
@types/office-js | |
[email protected]/dist/css/fabric.min.css | |
[email protected]/dist/css/fabric.components.min.css | |
[email protected]/client/core.min.js | |
@types/core-js | |
[email protected] | |
@types/[email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment