如何使“命令"按钮在Office外接程序中工作? [英] How to get 'Commands' button working in Office Addins?

查看:111
本文介绍了如何使“命令"按钮在Office外接程序中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,我用于按钮的任何功能都不起作用+我不知道如何调试Office命令.

I have issue that any function I use for button does not work + I don't know how to debug Office Commands.

Excel Version 1904 (build 11527.20004)

当我使用F12调试器并为我的插件(任务窗格)附加到IE进程时,然后当我单击按钮时,我将得到未处理的异常并提示附加调试器,如果我在VS 2017中这样做,会得到这个:

When I use F12 debugger and attach to the IE process for my addin (task pane), then when I click the button I'll get unhandled exception and prompt to attach debugger, If I do so with my VS 2017, I will get this:

第18行中第27179列的未处理异常 https://appsforoffice.microsoft.com/lib/1.1/hosted/office. js 0x800a01b6-JavaScript运行时错误:对象不支持属性 或方法过滤器"发生

Unhandled exception at line 18, column 27179 in https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'filter' occurred

我做了什么: -清单似乎正确(通过验证),它具有所有节点,功能区中的按钮均可见. -启用环回豁免(我将其与IIS服务器一起在我的本地主机上运行)后,对DesktopFunctionFile的引用似乎正常,提琴手显示已正确检索到它 -对于"ExecuteFunction",我使用了多种功能,例如 -显示自定义对话框(什么都没有发生) -将一些数据写入工作表(什么都没有发生) -任何使用过的console.log都不会显示在任何地方(我希望在运行时日志中看到它). -我使用event.completed();

What I did: - manifest seems correct (validation passed), it has all the nodes, buttons are visible in the ribbon. - after enabling loopback exemption (I run it on my localhost together with IIS server) reference to the DesktopFunctionFile seems fine, fiddler shows it is retrieved correctly - for the "ExecuteFunction" I used multiple functions like - Show Custom Dialog (nothing happens) - Write some data into the sheet (nothing happens) - any used console.log does not show anywhere (I was expecting to see it in the Runtime log). - I use the event.completed();

单击测试"按钮时,我只会在Excel底部看到"RibbonTest正在测试". "RibbonTest"是我插件的名称.

I only see "RibbonTest is working on Test" at the bottom of Excel when clicked on "Test" button. "RibbonTest" is name of my addin.

我将此示例用作我的'FunctionFile'html(只是头部)的基础: https://github.com/OfficeDev/Office-Add-in-Dialog-API-Simple-Example/blob/2304d66438323239eb81e61b734bd8b231cc4615/SimpleDialogSampleWeb/FunctionFile.html

I used this sample as a base for my 'FunctionFile' html (just head part): https://github.com/OfficeDev/Office-Add-in-Dialog-API-Simple-Example/blob/2304d66438323239eb81e61b734bd8b231cc4615/SimpleDialogSampleWeb/FunctionFile.html

<head> 
   <script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js" type="text/javascript"></script>
    <script>
        var clickEvent;
        // The initialize function must be defined each time a new page is loaded
        (function () {
            Office.initialize = function (reason) {
               // If you need to initialize something you can do so here.
            };
        })();
        // Wrap the writeToDoc in showNotification because showNotification is called
        // in DialogHelper.js but must be defined differently when the dialog is called
        // from a task pane instead of a custom menu command.
        function showNotification(event)
        {
            clickEvent = event;
            writeToDoc();
            //Required, call event.completed to let the platform know you are done processing.
            clickEvent.completed();
        }

        function writeToDoc()
        {
            console.log("WriteToDoc.");
            Excel.run(function (context) {
                var sheet = context.workbook.worksheets.getActiveWorksheet();
                var range = sheet.getRange("B2");
                range.values = [[ 5 ]];
                return context.sync();
            });
        }
    </script>
</head>

有人知道如何在Office加载项中调试命令"吗? 进行此运行的任何提示都非常受欢迎! 谢谢.

Does anyone know how to debug the 'Commands' in Office Addins? Any tip for getting this running is more than welcome! Thanks.

推荐答案

要调试外接程序命令的JavaScript,您需要

To debug the JavaScript of an Add-in Command, you need to debug it with Office Online.

这篇关于如何使“命令"按钮在Office外接程序中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆