//两个用到的方法
public ArrayList GetCurrentExcelProcess()
{
Process[] systemProcess;
ArrayList processIdArray = new ArrayList();
systemProcess = System.Diagnostics.Process.GetProcesses();
for (int i = 0; i <= systemProcess.Length - 1; i++)
{
if (systemProcess[i].ProcessName.ToString() == "EXCEL")
{
processIdArray.Add(systemProcess[i].Id);
}
}
return processIdArray;
}
public ArrayList GetDifficultExcelProcess(ArrayList lastProcess,ArrayList nowProcess)
{
ArrayList copyArrayList = new ArrayList();
copyArrayList = nowProcess;
for (int i = 0; i <= nowProcess.Count - 1; i++)
{
if (lastProcess.Contains(nowProcess[i]))
{
copyArrayList.Remove(nowProcess[i]);
}
}
return copyArrayList;
}
//定义两个ArrayList获取运行前后的Excel进程集合
ArrayList lastProcessArray = new ArrayList();
ArrayList nowProcessArray = new ArrayList();
lastProcessArray = GetCurrentExcelProcess();
//
// code for generate excel
//
//
nowProcessArray = uSystem.GetCurrentExcelProcess();
ArrayList difficultArray = new ArrayList();
difficultArray = GetDifficultExcelProcess(lastProcessArray, nowProcessArray);
for (int i = 0; i <= difficultArray.Count - 1; i++)
{
System.Diagnostics.Process runningProcess = new System.Diagnostics.Process();
runningProcess = System.Diagnostics.Process.GetProcessById(int.Parse(difficultArray[i].ToString()));
runningProcess.Kill();
}
导出,读取Excel后删除Excel进程。(保留原先的excel进程)
最新推荐文章于 2017-08-17 12:48:25 发布