2017-03-20 7 views
0

私はjsファイルselect()機能を介してコンテンツコントロールを選択しようとしている - docs - しかし、私は常にアクセス拒否エラーになっています。またWordのJS APIアクセスが拒否されました(ContentControl.select、Body.getHtml)

Error: 
{ 
    "name": "OfficeExtension.Error", 
    "code": "AccessDenied", 
    "message": "AccessDenied", 
    "traceMessages": [], 
    "debugInfo": 
    { 
     "errorLocation":"ContentControl.select" 
    }, 
    "stack":"AccessDenied: AccessDenied\n at Anonymous function (https://appsforoffice.microsoft.com/lib/1.1/hosted/word-win32-16.00.js:19:150094)\n at yi (https://appsforoffice.microsoft.com/lib/1.1/hosted/word-win32-16.00.js:19:163912)\n at st (https://appsforoffice.microsoft.com/lib/1.1/hosted/word-win32-16.00.js:19:163999)\n at d (https://appsforoffice.microsoft.com/lib/1.1/hosted/word-win32-16.00.js:19:163819)\n at c (https://appsforoffice.microsoft.com/lib/1.1/hosted/word-win32-16.00.js:19:162405)" 
} 
Debug info: {"errorLocation":"ContentControl.select"} 

body.getHtml()およびbody.getOoxml()は、同じアクセス拒否エラーを返します。

コードスニペット:

// Run a batch operation against the Word object model. 
Word.run(function (context) { 

    // Create a proxy object for the content controls collection. 
    var contentControls = context.document.contentControls; 

    // Queue a command to load the id property for all of the content controls. 
    context.load(contentControls, 'id'); 

    // Synchronize the document state by executing the queued-up commands, 
    // and return a promise to indicate task completion. 
    return context.sync().then(function() { 
     if (contentControls.items.length === 0) { 
      console.log('No content control found.'); 
     } 
     else { 
      // Queue a command to select the first content control. 
      contentControls.items[0].select(); 

      // Synchronize the document state by executing the queued-up commands, 
      // and return a promise to indicate task completion. 
      return context.sync() 
       .then(function() { 
        console.log('Selected the first content control.'); 
      }); 
     } 
    }); 
}) 
.catch(function (error) { 
    console.log('Error: ' + JSON.stringify(error)); 
    if (error instanceof OfficeExtension.Error) { 
     console.log('Debug info: ' + JSON.stringify(error.debugInfo)); 
    } 
}); 

は、第一に、私はそれが私のコードに何かかもしれないと思ったが、私はまたsnipper-explorerを試みたと同じ問題が現れました。 github.com/OfficeDev/office-js-snippet-explorer/issues/13 - - (ホスティングマニフェスト&アプリの両方のローカルおよびインターネット経由を試してみました)

誰かがgithubの中に同じ問題を報告したが、IEのセキュリティオプションを変更して解決策は、私の事件を解決しませんでした。

私のWordのバージョン - 16.0.4266.1001

答えて

0

Kamilzは、あなたはかなり古いビルドです。私はあなたの製品を更新することを強くお勧めします(ファイルの更新→更新、または指示hereに従ってください)。現在、最新ビルドは16.0.7870.2024です。私はちょうどあなたの例のようにあなたのコードを実行し、成功したので、これは主に時代遅れのビルドの問題です。 あなたのシナリオは2行のコードに要約でき、ホストに1回だけ移動できるので、コードを他のプラットフォームに最適にしたい場合は、常に最適化を試みるべきです。これをチェックしてください:上記のコードとまったく同じことを行う必要があります

Word.run(function (context) { 
 
     context.document.contentControls.getFirstOrNullObject().select(); 
 
     return context.sync(); 
 

 
    })
[OK]を。 これが役立つことを願っています!

関連する問題