/// <summary>
/// 编写者:孙二永
/// 编写日期:2006-09-17
/// 函数作用:杀死计算机上的所有用户自己开启的Excel进程
/// </summary>
public static void killExcel()
{
foreach(Process p in Process.GetProcessesByName("EXCEL"))
{
try
{
p.Kill();
}
catch
{
//在杀死非应用程序开启的进程时,会抛出错误,直接抛弃错误,不用处理。
}
}
}
/// <summary>
/// 设置报表打开时是否提示更新,都回答否
/// 日期:2006-09-17
/// </summary>
/// <param name="src">Excel的文件名</param>
/// <param name="App">excel的进程</param>
/// <returns></returns>
private static Workbook openExcelFile(string src,Application App)
{
Workbook Book=null;
//_Open方法的第二个参数设置false,那么报表提示是否更新链接时,一律回答否。
//针对个别报表不提示更新链接的情况,在catch块中进行处理。
try
{
Book=App.Workbooks._Open(src,
false,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
}
catch
{
Book=App.Workbooks._Open(src,
Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
}
return Book;
}