使用 Office JS Word 从对话框访问 word 文档上下文 API
Access word document context from dialog with Office JS Word API
我正在尝试从对话框中访问单词文档上下文,如下所示:
Office.context.document.setSelectedDataAsync("Hello World!",
function (asyncResult) {
var error = asyncResult.error;
if (asyncResult.status === Office.AsyncResultStatus.Failed){
write(error.name + ": " + error.message);
}
});
这不起作用,因为 setSelectedDataAsync 未定义。
在此处的文档中 https://dev.office.com/reference/add-ins/shared/officeui.displaydialogasync 它在底部 Design considerations "Do not use a dialog box to interact with a document. Use a task pane instead."
是否根本不可能从对话框访问完整 word 文档上下文,还是建议不要这样做?
理想情况下,我想向用户展示一个包含大量详细信息的条目列表,然后用户可以从中 select 一个条目,然后将一个文档插入到文档中。从技术上讲,我可以在 TaskPane 中执行此操作,但那里的 space 有限。如果可能的话,我真的很想在对话框中进行(尤其是因为我还有其他一些非常相似的要求)。
是否有机会以与 TaskPane 相同的方式与 word 文档进行交互?
您无法通过对话框与文档交互。
来自文档:
https://dev.office.com/docs/add-ins/develop/dialog-api-in-office-add-ins
The messageParent function is one of only two Office APIs that can be called in the dialog box. (The other is Office.context.requirements.isSetSupported)
所以基本上,您在对话框中所能做的就是 show/collect 一些数据并通过 messageParent
函数将其发送回父级。
您可以向用户显示所有选项,然后将选定的选项发送回父级 window,然后根据需要与文档进行交互。
我正在尝试从对话框中访问单词文档上下文,如下所示:
Office.context.document.setSelectedDataAsync("Hello World!",
function (asyncResult) {
var error = asyncResult.error;
if (asyncResult.status === Office.AsyncResultStatus.Failed){
write(error.name + ": " + error.message);
}
});
这不起作用,因为 setSelectedDataAsync 未定义。
在此处的文档中 https://dev.office.com/reference/add-ins/shared/officeui.displaydialogasync 它在底部 Design considerations "Do not use a dialog box to interact with a document. Use a task pane instead."
是否根本不可能从对话框访问完整 word 文档上下文,还是建议不要这样做?
理想情况下,我想向用户展示一个包含大量详细信息的条目列表,然后用户可以从中 select 一个条目,然后将一个文档插入到文档中。从技术上讲,我可以在 TaskPane 中执行此操作,但那里的 space 有限。如果可能的话,我真的很想在对话框中进行(尤其是因为我还有其他一些非常相似的要求)。
是否有机会以与 TaskPane 相同的方式与 word 文档进行交互?
您无法通过对话框与文档交互。
来自文档:
https://dev.office.com/docs/add-ins/develop/dialog-api-in-office-add-ins
The messageParent function is one of only two Office APIs that can be called in the dialog box. (The other is Office.context.requirements.isSetSupported)
所以基本上,您在对话框中所能做的就是 show/collect 一些数据并通过 messageParent
函数将其发送回父级。
您可以向用户显示所有选项,然后将选定的选项发送回父级 window,然后根据需要与文档进行交互。