1

我知道 Web Add in 项目尚不支持动态功能区按钮或菜单,想知道是否对此进行了任何改进。事实上,我的主要问题是:我正在尝试在对话框中运行我的网络插件,而不是在任务窗格中,但是当我尝试获取 Office Word 文档的自定义属性时,我可以从任务中执行此操作窗格,但不能在对话框上执行相同操作。当我尝试下面的代码时,我得到了 RichApi.Error:AccessDenied。我检查了域,但找不到任何问题。有什么建议吗?

    async function readCustomDocumentProperties5() {
            await Word.run(async (context) => {
                let properties = context.document.properties.customProperties;
                properties.load("key,type,value");


                await context.sync();

                for (var i = 0; i < properties.items.length; i++)
                    console.log(
                        "Property Name:" +
                        properties.items[i].key +
                        "; Type=" +
                        properties.items[i].type +
                        "; Property Value=" +
                        properties.items[i].value
                    );
          
            });
        }

错误:

Uncaught (in promise) RichApi.Error: AccessDenied
at new n (word-win32-16.01.js:26)
at n.i.processRequestExecutorResponseMessage (word-win32-16.01.js:26)
at word-win32-16.01.js:26
at async Dialog.html?_host_Info=Word$Win32$16.01$tr-TR$telemetry$isDialog$$0:47
at async readCustomDocumentProperties5 (Dialog.html?_host_Info=Word$Win32$16.01$tr-TR$telemetry$isDialog$$0:42)
4

1 回答 1

0

重要提示:您无权访问 iframe 或新窗口中的 office 上下文作为对话框。但是这里有一个解决方法。

execute function您正在使用一种类型从功能区打开对话框。对?

解决方案是在打开对话框的函数文件中进行修改。在 的帮助下Office.context.ui.messageParent(your object as json or whatever you need to pass)。因此,在单击按钮时,您会向函数文件发送消息,并且您可以访问那里的办公应用程序上下文。

于 2022-02-21T13:12:45.253 回答