Skip to content

Instantly share code, notes, and snippets.

@lightman76
Last active August 19, 2023 05:23
Show Gist options
  • Save lightman76/2515508dd5fcea986ec99802cb0f151e to your computer and use it in GitHub Desktop.
Save lightman76/2515508dd5fcea986ec99802cb0f151e to your computer and use it in GitHub Desktop.
Cannot delete an uneditable contentControl in Word Online
name: Delete a read-only content control
description: trying to demo a bug
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 = true;
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")
cc.cannotEdit = false;
let entryPara = cc.insertParagraph("All work and no play makes Jack a dull boy.", Word.InsertLocation.end);
cc.cannotEdit = true;
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
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
jquery@3.1.1
@types/jquery@3.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment