繁体   English   中英

使用 Word 任务窗格加载项时,类型“typeof Office”上不存在属性“actions”

[英]Property 'actions' does not exist on type 'typeof Office' When using Word task pane add-in

我的任务是为我们的 Word 插件添加一个附加功能。

我们正在尝试添加自定义快捷方式。

我使用了https://learn.microsoft.com/en-us/office/dev/add-ins/design/keyboard-shortcuts#configure-the-manifest上给出的代码,使用代码时我得到了错误:类型“typeof Office”上不存在属性“actions”

代码如下所示:

Office.actions.associate('SHOWTASKPANE', function () {
    return Office.addin.showAsTaskpane()
        .then(function () {
            return;
        })
        .catch(function (error) {
            return error.code;
        });
});

我查看了 Office.js 文件,看不到是否缺少任何内容。

非常感谢您的帮助

试试这个对我有用 npm install @types\/office-js --save-dev

"

可以将这些功能添加到全局 scope 并且不要使用操作会对您有所帮助。

function getGlobal() {
  return typeof self !== "undefined"
? self
: typeof window !== "undefined"
? window
: typeof global !== "undefined"
? global
: undefined;
}

let g = getGlobal()

g.SHOWTASKPANE= function () {
    return Office.addin.showAsTaskpane()
        .then(function () {
            return;
        })
        .catch(function (error) {
            return error.code;
        });
});;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM