如何把GridView导入execl中去
解决方案 »
- treeview不限级别无限循环栏目
- 救急。。。
- 关于配置本机IIS的问题
- 客户端发送的所有HTTP标头 能伪造吗?
- ASP.NET 客户端上传文件到服务端
- 关于获取当前控件名的一个问题?在线等!
- 帮忙看看这个问题,困扰我半天了
- GridView嵌套GridView,在第二个GridView中实现新增,编辑,更新等操作遇到了郁闷的问题?孟子E章上面那个问题的扩展
- 有用过web appliction stress tool(WAS)的老兄帮忙讲一下怎么用(定高分相谢)
- 如何动态生成HTMLINPUTFILEL 控件
- 请问如何将dataview中的数据采用带事务的存储过程存储到SQL数据表格中?
- 能否实现本机和Windows服务进行通讯,取得Windows服务的数据?多谢~~~
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
System.Web.HttpContext.Current.Response.Charset = "";
// If you want the option to open the Excel file without saving than
// comment out the line below
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.Web.HttpContext.Current.Response.ContentType = "application/" + filename;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
gw.RenderControl(htmlWrite);
System.Web.HttpContext.Current.Response.Write(stringWrite.ToString());
System.Web.HttpContext.Current.Response.End();
}
{
page.Response.Clear();
// 防止中文内容为乱码
page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
//可令中文文件名不为乱码
page.Response.AppendHeader("content-disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(Filename + DateTime.Now.ToShortDateString(), System.Text.Encoding.UTF8) + ".xls\"");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gridview.RenderControl(htw);
page.Response.Write(sw.ToString());
page.Response.End();
} 调用方法:类.ExportToExcel("中文文件名",GridView1,this.Page);