2017-07-27 142 views
0

我寫了調試puposes下面的代碼:爲什麼Office.EventType.DocumentSelectionChanged不一致速度慢?

(function() { 
    "use strict"; 

    // The initialize function is run each time the page is loaded. 
    Office.initialize = function (reason) { 


     $(document).ready(function() { 

      // Use this to check whether the API is supported in the Word client. 
      if (Office.context.requirements.isSetSupported('WordApi', 1.1)) { 
       // Do something that is only available via the new APIs 

       Office.context.document.addHandlerAsync(Office.EventType.DocumentSelectionChanged, onSelectionChanged); 
      } 
      else { 
       // Just letting you know that this code will not work with your version of Word. 
       $('#status').html('This code requires WordApi 1.1 or greater.'); 
      } 
     }); 
    }; 

    var c = 1; 
    function onSelectionChanged(eventArgs) { 
     c++; 
     $('#status').html('onSelectionChanged() call '+c+); 
    } 
})(); 

此代碼僅有時反應的變化。有時候會很慢。有時候(我猜如果它太慢了,並且它們之間有多重變化,它會在一段時間後不能識別它們並打印onSelectionChanged() call 4,即使已經發生了很多更改 其他時候,如果我關閉了Word,並重新打開它,它只是作爲一種魅力,然後我關閉它,再次打開它,並再次失敗 - 它是完全不一致的,因此這個功能是不可用的

我在不同的機器上測試過,不同版本的Windows和它的occures系統的利用率的影響無關。

任何想法?

回答

0

遺憾的是我沒能於r epro你的問題。該事件工作非常一致。

它沒有關係,但有沒有一個特定的原因,你爲什麼要檢查1.1的要求集?此事件在API的第一個發行版中發佈,因此不需要。

如果您可以提供您的內部版本號和示例文檔以及正在進行的操作的視頻,我們可以更詳細地進行調查。

謝謝!

+0

恐怕我不能分享這份文件。我試圖用其他許多文件重現問題並失敗。但是,我的整個加載項是圍繞此文檔構建的。 該文檔具有> 200頁,主要包含帶文本的表格。 –

+0

你在做什麼? –

+0

我的問題是16.0.4549.1000以及Word版本1706(Build 8229.2086)。現在我建立了一個解決方法,避免了事件。 –

相關問題