怎么判断用.NET打开Excel程序已经关闭,请详解
做一个WPF窗口小程序循环打开3个Excel,每次只打开1个,判断打开的EXCEL是否已经关闭,关闭后在打开下1个Excel代码:privatevoidbtnLoad_C...
做一个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);//阻止设定时间
}
} 展开
代码:
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);//阻止设定时间
}
} 展开
2017-07-05
展开全部
--ASP.NET导出Excel发布之后进程无法关闭--
追问
我这个不是web页,并且我想知道的是:
.NET打开EXCEL,怎样判断文档是否关闭
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询