本文介绍了等待Workbook.RefreshAll()(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想循环使用目录(使用C#)并刷新所有Excel表格。我使用:

I want to loop through a directory (using C#) and Refresh all Excel sheets in there. I use:

Workbook.RefreshAll();

如何等待 Workbook.RefreshAll()语句完成?


问题是:我打开 FileA then Workbook.RefreshAll() 然后打开 FileB - 刷新 FileA 终止。我找到的唯一解决方案是调用类似于

How can I wait for the Workbook.RefreshAll() statement to finish?

The problem is: I open FileA, then Workbook.RefreshAll() and then open FileB - Refresh for FileA is terminated. The only solution I found is to call something like

System.Threading.Thread.Sleep(20000);

我发现非常unlovely ...

which I found very unlovely...

有人知道更好的等待方式吗?

Does someone know a better way to wait?

推荐答案

更新31.05.2016 ...

Updated 31.05.2016...

感谢您的帮助。我找到以下解决方案:

Thanks for your help. I found the following solution:

foreach (MSExcel.WorkbookConnection cnn in wb.Connections)
{
    if (cnn.Type.ToString() == "xlConnectionTypeODBC")
    {
        cnn.ODBCConnection.BackgroundQuery = false;
    }
    else
    {
        cnn.OLEDBConnection.BackgroundQuery = false;
    }
}

Frank

这篇关于等待Workbook.RefreshAll()(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 16:39