In my Word Add-In, I want my user to be able to insert a template, with editable content controls. Works fine in Word client, but in Word online, I can't get it to work properly.
You'll find my code below. I get a debug error saying The action isn't supported in Word Online. Error location : ContentControl.placeholderText
.
Indeed when I comment out the line setting placeholderText, I get no error. But then my add-in only adds lines of empty text, which is not my purpose obviously.
Word.run(function (context) {
var thisDocument = context.document,
range = thisDocument.getSelection();
case "ProtagonistsIntroduction":
var paragraph = range.insertParagraph("Customer", Word.InsertLocation.before);
paragraph.styleBuiltIn = "Heading1";
setTemplateContentControlProperties(range, "Mr/Ms. and name", true);
//I insert here many other content controls
break;
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
function setTemplateContentControlProperties(container, placeholderText, lineBreakAfter) {
var contentControl = container.insertContentControl();
contentControl.appearance = "BoundingBox";
contentControl.removeWhenEdited = true;
contentControl.placeholderText = placeholderText;
if (lineBreakAfter) {
contentControl.insertBreak("Line", Word.InsertLocation.after);
}
return contentControl;
}
As this tool is here to provide the user with a document template with all the information that he should include, I need these placeholders. Is there a way around this ?
I would be OK with a way of just adding lines of text instead of content controls when in Word Online ; but adding the content controls when I'm in a compatible environment (Word client) ; if there isn't anything better than that.
Cheers !