2017-03-20 4 views
0

Ich versuche Inhaltskontrolle durch js select() Funktion wählen - docs - aber ich bin immer Zugriff verweigert Fehler bekommen:Wort JS api Zugriff verweigert (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"} 

Auch body.getHtml() und body.getOoxml() gibt den gleichen Access Denied-Fehler zurück.

Code-Snippet:

// 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)); 
    } 
}); 

Zuerst dachte ich, es ist etwas falsch mit meinem Code sein könnte, aber ich habe auch versucht, snipper-explorer und das gleiche Problem erschien. (versucht Hosting-Manifest & App sowohl lokal und über das Internet)

Jemand berichtete das gleiche Problem in Github - github.com/OfficeDev/office-js-snippet-explorer/issues/13 - aber Lösung mit wechselnden IE-Sicherheitsoptionen hat nicht meinen Fall zu lösen.

My Word-Version - 16.0.4266.1001

Antwort

0

Kamilz, Sie sind in einem recht alten zu bauen. Ich empfehle Ihnen dringend, Ihr Produkt zu aktualisieren (gehe zu Datei-> Update oder folgen Sie den Anweisungen here). Im Moment ist der neueste Build 16.0.7870.2024. Ich habe Ihren Code genau wie in Ihrem Beispiel ausgeführt und war erfolgreich, daher handelt es sich meistens um ein veraltetes Build-Problem. Das heißt, Ihr Szenario kann zu 2 Zeilen Code zusammengefasst werden, und nur 1 Reise zum Host, sollten Sie immer versuchen, dies zu optimieren, vor allem, wenn Sie möchten, dass Ihr Code optimal für andere Plattformen ist. Check this out:

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

 
    })
ok, die genau über das gleiche wie Ihr Code tun sollen. hoffe das hilft!