我们有一个产品支持 O365 windows 和 mac 使用 office js。现在在同一产品上,我们将在线支持 O365 word。在我们的工作中,我们发现 O365 windows 和 word online 存在一个差异。我们有一个文档,它在内容控件内有一个单词表。
在word online中,我们无法检索word表内的内容控件,但是,我们可以检索O365 windows和mac桌面中的所有内容控件。
以下代码片段在 O365 窗口和 mac 中正常工作,但在 word 在线中不工作。
$("#run").click(() => tryCatch(run));
function run() {
return Word.run(function (context) {
var contentControls = context.document.contentControls
context.load(contentControls, "id,text,title,tag,placeholderText");
return context.sync().then(function () {
/*console.log('The selected text was "' + contentControls.items.length + '".');*/
contentControls.items.forEach((contentControl: Word.ContentControl) => {
console.log('The Content control id "' + contentControl.id + '".');
});
});
});
}
/** Default helper for invoking an action and handling errors. */
function tryCatch(callback) {
Promise.resolve()
.then(callback)
.catch(function (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
});
}