gridView导出至excel,网页上多余的文本、图片都导进了excel,何解?
Response.Clear();Response.Buffer=true;Response.Charset="utf-8";Response.AppendHeader(...
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("ContentDisposition", "attachment;filename=tuican.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); //设置输出流为简体中文
Response.ContentType = "application/ms-excel";
gv.Page.EnableViewState = false;
gv.AllowPaging = false;
System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gv.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
//Response.End();
最后一句加上不会导入附加文本,但是只能导入gridview的第一页,以后的页都没导进去,什么原因,谢谢? 展开
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("ContentDisposition", "attachment;filename=tuican.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); //设置输出流为简体中文
Response.ContentType = "application/ms-excel";
gv.Page.EnableViewState = false;
gv.AllowPaging = false;
System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gv.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
//Response.End();
最后一句加上不会导入附加文本,但是只能导入gridview的第一页,以后的页都没导进去,什么原因,谢谢? 展开
3个回答
展开全部
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.Charset = "GB2312";
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.AllowPaging = false;//导出前先取消分页,以便能将所有数据导出。
BindGridView1();//再重新绑定一次数据
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
这段代码我用过,没问题
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.Charset = "GB2312";
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.AllowPaging = false;//导出前先取消分页,以便能将所有数据导出。
BindGridView1();//再重新绑定一次数据
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
这段代码我用过,没问题
展开全部
导出前关闭分页,导出后打开分页。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
强烈建议不要使用这种方式导出EXCEL这种并不是真正的EXCEL。右键记事本打开就会发现是些HTML代码。最好是制作一个EXCEL模版,然后写入数据。方便快捷。好用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询