http://blog.youkuaiyun.com/hefuren/archive/2007/12/01/1910433.aspx
#region 强制杀死EXCEL应用程序进程
/// <summary>
/// 强制杀死EXCEL应用程序进程
/// </summary>
private static void KillExcel()
{
int iProcessID=0;
String sProcessName="";
System.Diagnostics.Process[] pTemp;
pTemp=System.Diagnostics.Process.GetProcesses();
foreach ( System.Diagnostics.Process pTempProcess in pTemp)
{
sProcessName=pTempProcess.ProcessName;
iProcessID=pTempProcess.Id;
//将EXCEL改成你需要检测的程序名,不要加exe
if (sProcessName.CompareTo("EXCEL")==0)
{
pTempProcess.Kill();
pTempProcess.Close();
// break;
}
}
}
#endregion
}
}
public DataSet ExcleToDS_WS(string FilePath,string SheetName)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + FilePath + ";" +
";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = null;
DataSet ds = null;
conn.Open();
string sSQL = "";
string strDate=this.hidYM.Value.ToString();
ExcelFunc m_ExcelFunc=new ExcelFunc();
ds = new DataSet();
try
{
sSQL=string.Format("select * from [{0}$A7:E29]",SheetName);
myCommand = new OleDbDataAdapter(sSQL, strConn);
myCommand.Fill(ds,"WS_Supply");
sSQL=string.Format("select * from [{0}$F7:J20]",SheetName);
myCommand = new OleDbDataAdapter(sSQL, strConn);
myCommand.Fill(ds,"WS_Sell");
sSQL=string.Format("select * from [{0}$F26:J29]",SheetName);
myCommand = new OleDbDataAdapter(sSQL, strConn);
myCommand.Fill(ds,"WS_Other");
}
catch
{
Response.Write("<script language = javascript> alert('模版有误,请按模版填写!');</script>");
}
conn.Close();
return ds;
}
ExcleToDS_WS(string FilePath,string SheetName)函数中FilePath参数为Excel的物理路径,SheetName为Excel中
工作薄的名字。