2017-04-23 3 views
2

Ich versuche, den Titel und die Reihenfolge aller Inhaltssteuerelemente in einem Word-Dokument zu erhalten. Der folgende Code funktioniert:Ausnahme versucht, parentContentControlOrNullObject -Eigenschaft zu erhalten

function readContentControlsTitle() { 

    Word.run(function (context) { 
     var myDocParagraphs = context.document.body.paragraphs; 

     context.load(myDocParagraphs, 'text, outlineLevel'); 

     return context.sync().then(function() { 

      for (var i = 0; i < myDocParagraphs.items.length; i++) { 

       var parContentControl = myDocParagraphs.items[i].parentContentControlOrNullObject; 

       context.load(parContentControl, 'title'); 

       paragraphContentControls.push(parContentControl); 
      } 

      return context.sync().then(function() { 

       for (var iCount = 0; iCount < paragraphContentControls.length; iCount++) { 

        if (paragraphContentControls[iCount].title != null) { 
          // Some stuff with paragraphContentControls[iCount].title 
        } 
       } 

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

Das Problem entsteht, wenn ich ein Inhaltsverzeichnis in das Dokument einfüge. In diesem Fall bekomme ich immer eine Ausnahme im zweiten context.sync. Wenn ich das Inhaltsverzeichnis lösche, funktioniert es wieder. Der Ausgang der Ausnahme ist:

Debug-Info: { "Code": "GeneralException", "message": "GeneralException", "errorLocation": "Paragraph.parentContentControlOrNullObject"}

My Word-Version: 16.0 .7927.1020

Antwort

1

Vielen Dank, dass Sie das Problem erkannt haben. Ja, es ist ein Fehler. Es ist jetzt behoben und sollte nächsten Monat veröffentlicht werden. Vor dem Fix können Sie parentContentControlOrNullObject in try/catch setzen. Vielen Dank.

Verwandte Themen