作者:乔山办公网日期:
返回目录:excel表格制作
创建SQL语句
"SELECT TOP 65535 [uNo] AS ID, [uName] AS 姓名, [uSex] AS 性别 INTO [Excel 8.0;database=" + HttpContext.Current.Server.MapPath("../App_Data/Excel/") + @"down.xls].[excel表] FROM [student] ";
====================================================
执行sql语句,生e5a48de588b6e799bee5baa6e79fa5e98193334成excel文件
String strMDBcon =链接字符串;
OleDbConnection objMDBcon = new OleDbConnection(strMDBcon);
OleDbCommand objMDBcmd = new OleDbCommand(strSql, objMDBcon);
objMDBcon.Open();
objMDBcmd.ExecuteNonQuery();
objMDBcon.Close();
objMDBcon.Dispose();
====================================================
下载excel文件
//文件下载
System.IO.FileInfo fileInfo = new System.IO.FileInfo(Server.MapPath("../App_Data/Excel/down.xls"));
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=excel文件名.xls");
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();