2017-08-09 83 views
0

我得到每當我試圖讓款辦公應用程序的列表屬性以下錯誤:如何獲得列表樣式的段落在辦公室JS API

{ 
    "name": "OfficeExtension.Error", 
    "code": "ItemNotFound", 
    "message": "We couldn’ t find the item you requested. Check the OfficeExtension.Error.debugInfo for more information.", 
    "traceMessages": [], 
    "innerError": null, 
    "debugInfo": { 
     "code": "ItemNotFound ", 
     "message": "We couldn’ t find the item you requested.Check the OfficeExtension.Error.debugInfo for more information.", 
     "errorLocation ": "Paragraph._onAccess " 
    } 
} 

這裏是我使用的代碼:

var paragraphs = context.document.body.paragraphs; 
context.load(paragraphs, 'style'); 
return context.sync().then(function() { 
      var list = paragraphs.items[0].listOrNullObject; 
      context.load(list); 
      return context.sync().then(function() { 
       var item = list.levelTypes; 
       return context.sync().then(function() { 
        console.log("text" + item); 
       }); 

      }) 

如何獲取段的列表樣式?

回答

0

您沒有在Word.run上下文中運行。所有東西都應該在這個上下文範圍內,否則你的對象不會被填充。

來填充您的收藏款,試試這個:

Word.run(function (context) { 
     var paragraphs = context.document.body.paragraphs; 
     context.load(paragraphs); 
     return context.sync().then(function() { 
      // Process paragraphs here 
     }); 
    }) 
    .catch(function (error) { 
     console.log('Error: ' + JSON.stringify(error)); 
     if (error instanceof OfficeExtension.Error) { 
      console.log('Debug info: ' + JSON.stringify(error.debugInfo)); 
     } 
    }); 
+0

我運行在只有word.run上下文有關的代碼,並能夠訪問properties.Problem我面臨的只有相關的屬性訪問列表的段落,我得到了上述錯誤。我在在線辦公室365進行測試。 – user1461826