【发布时间】:2018-06-16 18:35:01
【问题描述】:
我在所有页面的word文档标题中插入了内容控件,但后来我注意到“contentcontrol.items.length”结果始终为1。它不应该等于页码吗?为什么总是一个?谁能解释一下?代码:
await Word.run(async (context) => {
var mySections = context.document.sections;
context.load(mySections, 'body/style');
await context.sync().then(function () {
var myHeader = mySections.items[0].getHeader("primary");
myHeader.clear();
myHeader.insertHtml('<a href="https://www.cgi.se/">CGI</a>',"Start");
var myContentControl = myHeader.insertContentControl();
myContentControl.tag = "header";
myContentControl.appearance = "Tags";
return context.sync();
});
});
然后来统计内容控件:
async function ContentControlCount() {
// Run a batch operation against the Word object model.
await Word.run(function (context) {
// Create a proxy sectionsCollection object.
var mySections = context.document.sections;
// Queue a commmand to load the sections.
context.load(mySections, 'body/style');
return context.sync().then(function () {
var myHeader = mySections.items[0].getHeader('primary');
return context.sync().then(function () {
var contentControl = myHeader.contentControls;
// Queue a command to load the text property for a content control.
context.load(contentControl, 'text, tag');
// Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
return context.sync().then(function () {
console.log(contentControl.items.length);
console.log(contentControl.items[0].text);
});
});
});
})
.catch(function (e) { console.log(e.message); })
}
【问题讨论】:
-
如果这是一个编码问题,那么添加您到目前为止的尝试。否则,它应该移动到superuser.com
-
代码已添加,谢谢。
-
谢谢。现在,您的问题是对我们知识库的宝贵贡献。
-
任何人都可以分享一些光?谢谢!
标签: wordpress office-js office-addins word-addins