Excel Interop:退出Excel應用程序實例會使我的測試失敗? - Excel Interop: Quitting the Excel application instance makes my tests fail? -开发者知识库

Excel Interop:退出Excel應用程序實例會使我的測試失敗? - Excel Interop: Quitting the Excel application instance makes my tests fail? -开发者知识库,第1张

I want to encapsulate the use of Excel Interop to make it easier to use somehow in a reuseable library.

我想封裝Excel Interop的使用,以便在可重用的庫中以某種方式使用它。

So far, I have written some tests that work good altogether, except that between each test, I force Excel to quite so that it does have handle on the test file no more in order to be able to delete.

到目前為止,我已經編寫了一些完全正常的測試,除了在每次測試之間,我強制Excel使其確實不再處理測試文件以便能夠刪除。

Once I quit the application instance between after each of my tests, Excel seems to be no longer responding, causing Windows to display

一旦我在每次測試之后退出應用程序實例,Excel似乎不再響應,導致Windows顯示

"Excel has stopped working and is looking for a solution"

“Excel已停止工作,正在尋找解決方案”

message. This message lasts a few seconds, meanwhile Excel is closing, causing the hang on the file to occur and my tests to throw an exception like

信息。此消息持續幾秒鍾,同時Excel正在關閉,導致文件掛起,我的測試拋出異常,如

"Cannot access file because it is being used by another process..."

“無法訪問文件,因為它正被另一個進程使用......”

message. Otherwise, each of my tests run individually just fine!

信息。否則,我的每個測試都單獨運行就好了!

Any clue on how to solve this issue?

關於如何解決這個問題的任何線索?

Do I overuse the ApplicationClass.Quit() method?

我是否過度使用ApplicationClass.Quit()方法?

Quitting Excel only once the testing is through with my tests causes the files created for the tests purpose not to be deleteable.

僅在測試通過我的測試后退出Excel會導致為測試目的創建的文件不可刪除。

Thanks! =)

2 个解决方案

#1


2  

If you've made changes to the Workbook then could it be the "Do you wish to save changes?" dialog which is holding things up. You could try setting the _Workbook.Saved property to True prior to quitting the application. See here for details

如果您對工作簿進行了更改,那么它可能是“您是否希望保存更改?”正在舉行的對話。您可以嘗試在退出應用程序之前將_Workbook.Saved屬性設置為True。詳情請見此處

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复