做一个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);//阻止设定时间
}
}