2017-08-09 20 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