HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Repeater1.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
导出的数据时这样的
怎样才能导出的只有数据,没有多余的代码
解决方案 »
- NET怎么实现查找一定的标记,然后用别的字符串替换掉
- DataGrid ItemCommand 索引超出范围。必须为非负值并小于集合大小。参数名: index(救命啊!!!!!)
- 在网页中如何实现js调用webservice后马上返回,而webservice继续作业。
- 大家看看这个人网站做的如何:http://www.lizheng.17chwl.com
- 可以这样用datagrid的ItemDataBound事件吗?
- SOS!!在一个框架网页内嵌套打印后,如何屏蔽其中某个框架,使其在打印时不显示(不会打印出来)?
- 请问我想限制textbox输入的东西,要怎么做?
- 谁给个WCF实例
- 我的第一分工作要除脱了拉,救我。。。
- 很简单的问题?
- 找不到存储过程 'proc_getpagedata'。
- Request.ApplicationPath
http://fineui.com/demo/#/demo/grid/grid_excel_aspnet.aspx
如果是用NOPI请参考
http://blog.csdn.net/apollokk/article/details/8025611
http://www.cnblogs.com/insus/archive/2013/01/16/2862121.html
Response.BufferOutput = true; //设定输出字符集
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
//设置输出流HttpMiME类型(导出文件格式)
Response.ContentType = FileType;
//关闭ViewState
Page.EnableViewState = false;
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter);
Repeater1.RenderControl(textWriter);
//把HTML写回游览器
Response.Write(stringWriter.ToString());
Response.End();
Response.Flush();