qq_36182585
北山有海
采纳率0%
2017-07-05 01:40

怎么判断用.NET打开Excel程序已经关闭

做一个WPF窗口小程序循环打开3个Excel,每次只打开1个,判断打开的EXCEL是否已经关闭,关闭后在打开下1个Excel
代码:
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
MainWindow obj = new MainWindow();
Thread thread = new Thread(new ThreadStart(obj.OpenOneExcel));
thread.Start();
}

    public List<int> listIDs = new List<int>() { 1053, 1054, 1055 };

    private void OpenOneExcel()
    {
        while (true)
        {
            Microsoft.Office.Interop.Excel.Application Eapp = new Microsoft.Office.Interop.Excel.Application(); //引用Excel对象
            string wjm = HospContext.GetFileName(listIDs[0]);//根据ID获取文件名例:fb/20170705.xls

            FileStream fs = new FileStream(wjm, FileMode.OpenOrCreate, FileAccess.Read);
            Microsoft.Office.Interop.Excel.Workbook book = Eapp.Application.Workbooks.Add(wjm);//知道Excel路径
            Microsoft.Office.Interop.Excel.Worksheets WSheet;
            Eapp.Visible = true;

            Thread.CurrentThread.Join(100);//阻止设定时间
        }

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 4年前

    Process.GetProcesses返回进程列表,看里面有没有excel

    点赞 评论 复制链接分享