【发布时间】:2018-04-11 02:13:54
【问题描述】:
在我的 Word 加载项中,我希望我的用户能够插入带有可编辑内容控件的模板。在 Word 客户端中运行良好,但在 Word 在线版中无法正常运行。
您会在下面找到我的代码。我收到一个调试错误,提示 The action isn't supported in Word Online. Error location : ContentControl.placeholderText。
实际上,当我注释掉行设置 placeholderText 时,我没有收到任何错误。但是我的插件只添加了空文本行,这显然不是我的目的。
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;
}
由于此工具旨在为用户提供文档模板,其中包含他应包含的所有信息,因此我需要这些占位符。 有没有办法解决这个问题?
我可以在 Word Online 中添加文本行而不是内容控件;但是当我在兼容的环境(Word 客户端)中时添加内容控件;如果没有比这更好的了。
干杯!
【问题讨论】:
标签: javascript office-js