用于Office的JavaScript API getFileAsync函数未调用回调

时间:2015-08-18 17:05:44

标签: javascript office365 office365-apps office365api javascript-api-for-office

我开发了一个非常简单的taskPane加载项,我想在Excel Online中测试。我使用Visual Studio 2015和Javascript Api for Office,我开始了一个新项目Office / Sharepoint - >然后我选择了任务窗格选项。 我改变他们构建的样本的唯一方法是在Home.js:

/// <reference path="../App.js" />

(function () {
    "use strict";

    // The initialize function must be run each time a new page is loaded
    Office.initialize = function (reason) {
        $(document).ready(function () {
            app.initialize();

            $('#get-crazy').click(getCrazy);
        });
    };

    // Reads data from current document selection and displays a notification
    function getCrazy(){
        Office.context.document.getFileAsync(Office.FileType.Compressed, {sliceSize: 2097152},
            function (result) {
                if (result.status === Office.AsyncResultStatus.Succeeded) {
                    console.log("I'm here :D ");
                } else {
                    app.showNotification('Error:', result.error.message);
                }
            }
        );
    }
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <title></title>
    <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>

    <link href="../../Content/Office.css" rel="stylesheet" type="text/css" />
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>

    <!-- To enable offline debugging using a local reference to Office.js, use:                        -->
    <!-- <script src="../../Scripts/Office/MicrosoftAjax.js" type="text/javascript"></script>  -->
    <!-- <script src="../../Scripts/Office/1.1/office.js" type="text/javascript"></script>  -->

    <link href="../App.css" rel="stylesheet" type="text/css" />
    <script src="../App.js" type="text/javascript"></script>

    <link href="Home.css" rel="stylesheet" type="text/css" />
    <script src="Home.js" type="text/javascript"></script>
</head>
<body>
    <div id="content-header">
        <div class="padding">
            <h1>Welcome</h1>
        </div>
    </div>
    <div id="content-main">
        <div class="padding">
            <button id="get-crazy"> SURPRISE! </button>
        </div>
    </div>
</body>
</html>

我还更改了清单,因此它的startAction指向InternetExplorer,我正在使用sharePoint开发人员站点打开此Excel Online。 当我运行代码时,我得到了这样的消息:

XML5619: Incorrect document syntax.
Line: 1, Column 1
SEC7111: HTTPS security is compromised by res://ieframe.dll/http_500.htm
SEC7111: HTTPS security is compromised by res://ieframe.dll/ErrorPageTemplate.css
SEC7111: HTTPS security is compromised by res://ieframe.dll/errorPageStrings.js
SEC7111: HTTPS security is compromised by res://ieframe.dll/httpErrorPagesScripts.js
SEC7111: HTTPS security is compromised by res://ieframe.dll/info_48.png
SEC7111: HTTPS security is compromised by res://ieframe.dll/bullet.png
SEC7111: HTTPS security is compromised by res://ieframe.dll/bullet.png
SEC7111: HTTPS security is compromised by res://ieframe.dll/down.png
SEC7111: HTTPS security is compromised by res://ieframe.dll/down.png
SEC7111: HTTPS security is compromised by res://ieframe.dll/background_gradient.jpg

当我按下按钮时,我只有这个:Agave.HostCall.IssueCall。而且我知道它在getFileAsync函数中“卡住了”..你能帮帮我吗?

2 个答案:

答案 0 :(得分:0)

您是否尝试使用Excel的本地副本而不是在线Excel,只是为了查看这是否是问题?

答案 1 :(得分:0)

你应该使用office.js 1.1版,因为1.1支持getFileAsync(),所以你应该替换&#34; https://appsforoffice.microsoft.com/lib/1/hosted/office.js&#34; by&#34; https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js&#34;。