Wait for Workbook.RefreshAll() (C#)

前端 未结 4 737
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 15:50

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

Workbook.RefreshAll();

How can I wait for the <

4条回答
  •  旧巷少年郎
    2021-01-18 16:32

    The below code will work perfectly when your excel has to run background query to pull data from SQL Server/MS Access and it will wait for the query is successful.

    public void RefreshSheet(Excel.Application Excel, Excel.Workbook WB)
    {
        WB.RefreshAll();
        Excel.Application.CalculateUntilAsyncQueriesDone();
        WB.save();
    }
    

    Here WB is the workbook and Excel is the Excel Application declared in your code.

提交回复
热议问题