Worksheets.load(“ items”)失败,导致访问被拒绝错误

时间:2019-08-05 15:51:04

标签: typescript office365 office-js office-addins

我正在处理一个暂停了很长时间的Excel加载项项目。当我停止工作时,它工作正常,但是现在我收到以下错误消息:

AccessDenied: You don't have sufficient permissions for this action.

通过控制台日志记录,我可以从WorksheetCollection获取context并打印对象,但是当我尝试加载items属性然后使用它时,访问被拒绝错误。

该错误对象不是很有帮助,但是堆栈跟踪指向office-js库。我正在使用本地静态版本。

相关代码App.tsx

try {
    var start = +new Date()

    await Excel.run( async context => {
      await this.append_message("Starting")
      var sheets = context.workbook.worksheets
      console.log(sheets)
      sheets.load("items"); await context.sync();

      for ( var i in sheets.items ) {
        let sheet = sheets.items[i]
        ...
        (logic goes here)
        ...
} catch (error) {
    //OfficeHelpers.UI.notify(error);
    OfficeHelpers.Utilities.log(error);
    await this.append_message("Something went wrong: "+ error)
    console.log("Debug info: " + JSON.stringify(error.debugInfo));
  }

manifest.xml几乎是默认的/带有URL更改的示例。权限是:

<Permissions>ReadWriteItem</Permissions>

摘录自Package.json

 "start": "webpack-dev-server --inline --mode development --config config/webpack.dev.js --progress --host 0.0.0.0",
...
"devDependencies": {
    "@types/office-js": "0.0.155",
    "@types/react": "^16.8.12",
    "@types/react-dom": "^16.8.0",
    "@types/react-hot-loader": "^4.1.0",
    "@types/webpack": "4.4.22",
    "@types/webpack-dev-server": "3.1.1",

Office版本:

Microsoft Office 365 Business, Version 1907 (Build 11901.20176 Click-to-Run)

操作系统:

 Microsoft Windows 10 Pro, 10.0.17134 Build 17134

编辑:

我切换到CDN版本,该版本不能完全解决问题,但似乎已经改变了某些地方。

首先,如果我不加载items属性,我仍然无法继续。这是错误消息:

PropertyNotLoaded: The property 'items' is not available. Before reading the property's value, call the load method on the containing object and call "context.sync()" on the associated request context.

第二,出现AccessDenied错误的位置已经移动。我还无法弄清楚到底是在哪里引发错误,但是现在我可以获得所有工作表和行。

0 个答案:

没有答案