2016-06-28 7 views
1

Word用の.NET MVCプロジェクトがオンラインです。アドインは正常に起動しますが、Office.initializeを呼び出してWordの本文にデータを挿入する "Home.js"は読み込まれません。Office.js関数がWord OnlineのMVCアプリケーションで動作しない

<html> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title></title> 
    @Styles.Render("~/bundles/css") 
    @Scripts.Render("~/bundles/modernizr") 
</head> 
<body ng-app=""> 
    <div class="container"> 
     @RenderBody() 
    </div> 
    @Scripts.Render("~/bundles/jquery") 
    @Scripts.Render("~/Scripts/Office/1/office.js") 
    @Scripts.Render("~/Scripts/Home.js") 
    @Scripts.Render("~/bundles/bootstrap") 
    @Scripts.Render("~/Scripts/angular.min.js") 
</body> 
</html> 

そしてHome.js:ここ

は_Layout.cshtmlある

(function() { 
    "use strict"; 

    Office.initialize = function (reason) { 
     $(document).ready(function() { 
      if (!Office.context.requirements.isSetSupported('WordApi', '1.1')) { 
       return; 
      } 
      loadSampleData(); 
     }); 
    }; 

    function loadSampleData() { 

     // Run a batch operation against the Word object model. 
     Word.run(function (context) { 
      // Create a proxy object for the document body. 
      var body = context.document.body; 
      // Queue a commmand to clear the contents of the body. 
      body.clear(); 
      // Queue a command to insert text into the end of the Word document body. 
      body.insertText("This is a sample text inserted in the document", 
          Word.InsertLocation.end); 

      // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion. 
      return context.sync(); 
     }) 
     .catch(errorHandler); 
    } 

    function errorHandler(error) { 
     console.log("Error: " + error); 
     if (error instanceof OfficeExtension.Error) { 
      console.log("Debug info: " + JSON.stringify(error.debugInfo)); 
     } 
    } 
})(); 

ありがとうございました。

+0

また、角度ブートストラップの問題についてもお答えしたいと思います。私はアプリケーションの角度を完全に取り除こうとしましたが、問題は解決しません。 – michaelmilone

+0

home.jsの読み込みはまったくですか?つまり、一番上にconsole.logを置くと、それは印刷されますか?はいの場合、console.logをOffice.initialzeの最初の行に置くと印刷されますか?返信ありがとうございます。 –

+0

はい、印刷されます。 – michaelmilone

答えて

0

WordAPI v1.1が利用可能な場合のみ実行しています。このAPIはWord 2016 for Windows, Mac and iPadでのみサポートされています。 Word OnlineまたはWord 2013を使用している場合、このコードは何も実行せずに終了します(return)。

<body>の下部にあるOffice.jsとHome.jsを参照しています。 Office.initialize()を完了するのに5秒しかかからず、ページの最下部に配置すると、ブラウザがその機能を実行する前にすべての読み込みが必要になります。これはWebサイトでは絶対に必要なことですが、アドインではタイムアウトエラーが発生します。これらの参考文献should always be placed within the <header>

+0

で真実を返すだけです、非常に良い、ありがとうあなたはマーク! – michaelmilone

関連する問題