2016-08-25 36 views
1

我已經爲運行搜索的單詞創建了一個任務窗格插件,並將選擇兩個搜索結果之間的文本。這裏推薦https://github.com/OfficeDev/office-js-docs/tree/WordJs_1.3_Openspec 和正在運行range.expand如何在javascript api中使用

Error: {"name":"OfficeExtension.Error","code":"InvalidArgument","message":"InvalidArgument","traceMessages":[],"debugInfo":{"errorLocation":""},"stack":"InvalidArgument: InvalidArgument\n at Anonymous function (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:183512)\n at pi (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:198624)\n at ht (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:198711)\n at g (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:198531)\n at l (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:19:197117)"} 

我使用PreviewCDN:但是現在

function onExpandTestClick() { 

     var textToFind = "Word", 
      range; 
     return Word.run(function(context) { 

      var searchResults = context.document.body.search(textToFind, { matchWildCards: false }); 
      context.load(searchResults, "text"); 
      return context.sync() 
       .then(function() { 
        range = searchResults.items[0].getRange("End"); 
        var rangeEnd = searchResults.items[1].getRange("Start"); 
        range.expandTo(rangeEnd); 
        context.load(range, 'text'); 
        return context.sync(); 
       }) 
       .then(function() { 
        range.select(); 
        return context.sync(); 
       }); 
     }) 
     .catch(function (error) { 
      console.log('Error: ' + JSON.stringify(error)); 
      } 
     }); 
    } 

被拋出以下錯誤: 直到前兩天下面的代碼成功運行office version 16.0.7167.2040

這是使用range.expandTo方法的正確方法嗎?或者在api中改變了一些東西?

回答

1

您正在使用該方法,雖然設計中會稍有變化。 ExpandTo的語義(正如您在最新文檔中看到的),它不會修改調用範圍,但會返回新擴展的範圍。

此更改需要更新Office.js庫,現在似乎是Beta CDN存在問題,我們正在更新它,以便它與當前公開可用的版本相匹配。

所以在這一點上我的建議是等待這個修復。

謝謝!

相關問題