GYYW.DA.Common.Base_SqlDataBase daBZDM =
new
GYYW.DA.Common.Base_SqlDataBase();
DataSet dsBZDM = daBZDM.GetDataSetBySql(
"select QCDM,MC,GG from WG_BZDM where QCDM like '02%'"
);
string
urlPath = HttpContext.Current.Request.ApplicationPath +
"/Data/"
;
string
physicPath = HttpContext.Current.Server.MapPath(urlPath);
string
fileName =
"DownLoad.Xls"
;
string
connString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ physicPath + fileName +
";Extended Properties=Excel 8.0;"
;
OleDbConnection objConn =
new
OleDbConnection(connString);
OleDbCommand objCmd =
new
OleDbCommand();
objCmd.Connection = objConn;
objCmd.Connection.Open();
objCmd.CommandText =
@"CREATE TABLE Sheet1(器材代码 varchar,名称 varchar, 规格 varchar)"
;
objCmd.ExecuteNonQuery();
objCmd.CommandText =
"INSERT INTO Sheet1(器材代码, 名称,规格) VALUES (@QCDM, @MC, @GG)"
;
objCmd.Parameters.Clear();
objCmd.Parameters.Add(
new
OleDbParameter(
"@QCDM"
, OleDbType.VarChar));
objCmd.Parameters.Add(
new
OleDbParameter(
"@MC"
, OleDbType.VarChar));
objCmd.Parameters.Add(
new
OleDbParameter(
"@GG"
,OleDbType.VarChar));
foreach
(DataRow row
in
dsBZDM.Tables[0].Rows)
{
for
(
int
i=0; i<objCmd.Parameters.Count; i++)
{
objCmd.Parameters[i].Value = row[i];
}
objCmd.ExecuteNonQuery();
}
objCmd.Connection.Close();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.WriteFile(urlPath + fileName);
string
httpHeader=
"attachment;filename=KCMX.Xls"
;
response.AppendHeader(
"Content-Disposition"
, httpHeader);
response.Flush();
string
strSaveDir =
"../Data/"
;
string
strFile = Server.MapPath(strSaveDir + fileName).ToString();
System.IO.File.Delete(strFile);
response.End();