2017-09-15 2 views
0

Je suis en train de développer un complément pour word.J'essaie de remplacer un signet par un texte (mon objectif initial était d'insérer du texte dans le signet, mais il y a un bogue dans l'API donc c'est l'autre approche. Earlier question link)Impossible de remplacer le signet dans un document Word à l'aide de office.js

Voici mon code-

Word.run (fonction (contexte) {

var doc = context.document; 

//get the bookmark range object by its name 
var bookmarkRange=doc.getBookmarkRangeOrNullObject("cscasenumber01"); 

//insert a data and replace thee bookmark range 
bookmarkRange.insertText("test data",Word.InsertLocation.replace); 

// Synchronize the document state by executing the queued commands, 
return context.sync(); 

}).catch(errorHandler); 

Mais il jette trace d'erreur exception.The message is- "GeneralException: GeneralException at An fonction Onymous (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:211625) à Aï (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:248841) à pieds (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:248928) à d (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:248748) à c (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:247444) »

est donc là une solution pour elle ou il est un autre bogue dans l'API?

Remarque: J'utilise la version 1.4 bêta de l'API office.js.

+0

Pouvez-vous utiliser la version publiée de l'API? –

Répondre

1

Vous devez tester si bookmarkRange est un objet nul. S'il vous plaît essayez ce code:

var bookmarkRange=doc.getBookmarkRangeOrNullObject("cscasenumber01"); 
bookmarkRange.load(); 

return context.sync() 
.then(function() { 
    if (bookmarkRange.isNullObject) { 
     // handle case of null object here 
    } else { 
     bookmarkRange.insertText("test data",Word.InsertLocation.replace); 
    } 
}) 
.then(context.sync) 
+0

Oui. Il ne donne pas d'objet nul.J'ai testé ton code mais pas de chance.Pourtant il donne la même exception. – reza