Asp.net成功导出Excel
来源:互联网 发布:卫生部数据查询 编辑:程序博客网 时间:2024/06/14 07:04
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new SqlDBhelper().queryallds("select * from tb_shop");
DataTable dtData = ds.Tables[0];
dtData.Columns.Remove("s_img");
dtData.Columns.Remove("s_bigimg");
dtData.Columns.Remove("type_id");
dtData.Columns.Remove("type_name");
//以下注释为加密字段,可写可不写
//foreach (DataRow drData in dtData.Rows)
//{
// drData["Password"] = DESEncrypt.DecryptPsw(drData["Password"].ToString());
//}
dtData.AcceptChanges();
System.Web.UI.WebControls.GridView dgExport = null;
System.Web.HttpContext curContext = System.Web.HttpContext.Current;
System.IO.StringWriter strWriter = null;
System.Web.UI.HtmlTextWriter htmlWriter = null;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding("utf-8");
curContext.Response.ContentType = "application/vnd.ms-excel";
string fileName = "SurveySubject_" + DateTime.Now.ToFileTimeUtc() + ".xls";
curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
curContext.Response.Charset = "";
strWriter = new System.IO.StringWriter();
htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
dgExport = new System.Web.UI.WebControls.GridView();
dgExport.DataSource = dtData.DefaultView;
dgExport.AllowPaging = false;
dgExport.DataBind();
dgExport.RenderControl(htmlWriter);
curContext.Response.Write(strWriter.ToString());
curContext.Response.End();
}
- Asp.net成功导出Excel
- asp.net导出excel
- asp.net导出Excel
- asp.net导出excel
- asp.net导出Excel
- Asp.net 导出Excel
- asp.net导出excel
- asp.net 导出excel
- asp.net 导出Excel
- asp.net 导出 excel
- asp.net导出Excel
- ASP.NET Excel导出
- asp.net导出EXCEL
- ASP.NET Excel导出
- asp.net 导出Excel
- asp.net 导出Excel
- Asp.net导出Excel
- asp.net导出excel
- Turbo C 2.0 使用指南
- LINUX netlink机制
- MySQL笔记
- WebView的应用
- myeclipse 常用快捷键
- Asp.net成功导出Excel
- hello,Kernel!
- Javascript笔记
- 常用数据库的字段类型及大小
- oracle_rowid_rownum
- linux system C language operate sqlite3
- 网站上有一个mp3文件,但是用<a href="my.mp3">下载</a>时,会在播放器里打开,请问我要怎样才能实现点击后下载呢?
- ECG - Android wireless
- 如何在基于 MFC 的 ActiveX 控件激发事件,在 Visual c + + 中的启动另一个线程