我正在尝试使用某些控件制作Word加载项,我想在内容控件中检索值,在这种情况下,它将是“ Hello”。
Word.run(async function (context) {
// Add Content Control
var blankParagraph = context.document.body.insertText("Hello", "End");
blankParagraph.insertContentControl();
blankParagraph.title = "Content";
blankParagraph.tag = "serviceName";
// Retrieve content control
var serviceNameContentControl = context.document.contentControls.getByTag("serviceName")
console.log(serviceNameContentControl);
return context.sync();
})
.catch(function (error) {
console.log("Error: " + error);
});
尽管,当我尝试在控制台中记录此文本的值时,属性“ items”显示错误。请查看下面的屏幕截图。
有人可以帮我解决这个问题吗?
您必须先加载属性,然后调用上下文同步,然后才能读取它。这就是错误消息的含义。有关更多详细信息,请参见Sychronizing Word documents with Word JavaScript API proxy objects。