在Excel中刷新全部无法使用睡眠 [英] Refresh All in Excel is not working with out Sleep

查看:146
本文介绍了在Excel中刷新全部无法使用睡眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.DisplayAlerts = false;
Workbook theWorkbook = excelApp.Workbooks._Open(XlsxPath, 0, false, 5, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, true, false, System.Reflection.Missing.Value, false);
Sheets sheets = (Sheets)theWorkbook.Worksheets;
theWorkbook.RefreshAll();
System.Threading.Thread.Sleep(Convert.ToInt32(60000));
theWorkbook.Save();
excelApp.Quit();



工作正常但流动不通用


is working fine but the flowing is not working

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.DisplayAlerts = false;
Workbook theWorkbook = excelApp.Workbooks._Open(XlsxPath, 0, false, 5, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, true, false, System.Reflection.Missing.Value, false);
Sheets sheets = (Sheets)theWorkbook.Worksheets;
theWorkbook.RefreshAll();
theWorkbook.Save();
excelApp.Quit();





为什么请帮助我,我不想包括



Why please help me i don't want to include

System.Threading.Thread.Sleep(Convert.ToInt32(60000));





因为我不知道需要多长时间才能刷新



请帮帮我





谢谢

Sudheer.N



because i don't know how much time it will take for refreshing

Please help me


Thanks
Sudheer.N

推荐答案

你好Sudheer,



RefreshAll行为取决于底层对象的BackgroundQuery属性。



如果BackgroundQuery设置为true然后RefreshAll立即返回结果。



因此请使用以下代码刷新不在后台的数据:



Hi Sudheer,

RefreshAll behaviour depends on the BackgroundQuery property of underlying objects.

If BackgroundQuery is set to true then RefreshAll returns the result immediately.

So use the following code to refresh data not in the background:

foreach (Worksheet ws in theWorkbook.Worksheets)
    foreach (ListObject lo in ws.ListObjects)
    {
        QueryTable qt = lo.QueryTable;
        if (qt != null)
        {
            qt.Refresh(false);
        }
    }




foreach (PivotCache pc in theWorkbook.PivotCaches())
{
    pc.Refresh();
}


这篇关于在Excel中刷新全部无法使用睡眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆