Office加载项命令ExecuteFunction操作未运行word.run

时间:2017-08-16 10:57:29

标签: office-js

我想在我的加载项中使用Office加载项命令。我用过 this example作为模板。

我计划更改ExecuteFunction按钮以运行一个功能,该功能会在文档中添加一个新字符串。所以我更改了writeText函数,代码如下所示。

当我点击按钮时,没有任何反应。什么可能导致这个?

- 更新 -

我正在努力调试这个 - 没有找到办法用F12做到这一点,因为它没有通过浏览器作为任务窗格加载。 最后在throw visual studio中调试 - 问题是我使用了:Office.context.document.body而不是函数的context参数。

问题可以解决。 谢谢大家!

------------------------------

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <!--During development turn off caching-->
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />
    <title></title>

    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
    <script>
        // The initialize function must be run each time a new page is loaded
        (function () {
            Office.initialize = function (reason) {
                //If you need to initialize something you can do so here. 
            };
        })();

        function writeText(event) {
            Word.run(function (context) {
                    var body = Office.context.document.body;
                    body.insertText('Test', 'Start');
                    return context.sync();
                })
                .catch(function (error) {
                    console.log('Error: ' + JSON.stringify(error));
                    if (error instanceof OfficeExtension.Error) {
                        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
                    }
                });
            event.completed();
        }
    </script>
</head>
<body>
    Function file body is never displayed.
</body>
</html>

0 个答案:

没有答案