GridView导出数据成Excel的时候提示:“单元格数据太大“,打开Excel,则出现乱码:
ps:我分页有600页数据。GridView导出数据成Excel
ps:我分页有600页数据。GridView导出数据成Excel
解决方案 »
- 关于新闻附件表关联新闻表的问题
- 各位高手帮帮忙!!急。。。。。。。
- 请教ajax的基本顺序问题
- 关于在ASP.NET中获得IP的问题
- 高手救命.....样式文件在IE6中部分失效(包括一些Td,div),但在IE7中可以,.net2.0母板形式开发.
- 有些人,真是的,可怜一下别人写作辛苦,尊重一下原创吧。
- 如何让表单上输入框的约束条件由后台数据库对应字段的数据类型或约束条件自动确定?
- 用下面这段代码导出"水晶报表"时为什么会连续弹出两个"提示保存的对话框"而不是只弹出一个?
- 成都的.net的一些职位(架构与teamleader)
- asp.net 调试问题,在线等
- MVC 关于不同数据库相同名称的表,在定义实体是遇到的问题
- .NET动态生成textbox控件
如何分sheet导出?
private void Export(string FileType, string FileName)
{
GridView1.AllowPaging = false;//设置为不分页
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw); GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
GridView1.AllowPaging = true;//设置为为分页 }//导出按钮所执行的方法
protected void ExporttoExcel_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "Report.xls");
}
所以分SHEET来也就不能用以上的代码了,网上这类的比较多,你找一下按SHEET导出EXCEL的例子。
http://www.cnblogs.com/mikehhs/archive/2011/12/14/2287263.html参考一下这个。
如图所示:
在导出Excel的代码上把
“ Response.ContentEncoding = System.Text.Encoding.UTF7;”这句换成“Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");”
应该就可以导出了。
在导出Excel的代码上把
“ Response.ContentEncoding = System.Text.Encoding.UTF7;”这句换成“Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");”
应该就可以导出了。 不过就是导出的时候只导出了第一页,看我上面的代码不是在导出之前已经设置为不分页了吗?
GridView1.AllowPaging = false;//设置为不分页
http://www.cnblogs.com/insus/archive/2009/02/28/1400266.html