GridView导出数据成Excel的时候提示单元格数据太大
GridView导出数据成Excel的时候提示:“单元格数据太大“,打开Excel,则出现乱码:ps:我分页有600页数据。 GridView导出数据成Excel --------------------编程问答-------------------- 600页有多少条?是不是超出了一个sheet的最大长度?分sheet导出吧 --------------------编程问答-------------------- 每页30条,600页就是18000行。
如何分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具体装多少我也忘记了, GridView1.AllowPaging = true;//设置为为分页这个代码已经无效了,你上面已经按不分页来的。
所以分SHEET来也就不能用以上的代码了,网上这类的比较多,你找一下按SHEET导出EXCEL的例子。
http://www.cnblogs.com/mikehhs/archive/2011/12/14/2287263.html参考一下这个。 --------------------编程问答-------------------- 你这个不是数据的问题,应该是导出的Excel用2003以上版本打开导致的,我的也出现个这种问题,
如图所示:
在导出Excel的代码上把
“ Response.ContentEncoding = System.Text.Encoding.UTF7;”这句换成“Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");”
应该就可以导出了。 --------------------编程问答-------------------- 确实如6楼所说:
在导出Excel的代码上把
“ Response.ContentEncoding = System.Text.Encoding.UTF7;”这句换成“Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");”
应该就可以导出了。
不过就是导出的时候只导出了第一页,看我上面的代码不是在导出之前已经设置为不分页了吗?
GridView1.AllowPaging = false;//设置为不分页
--------------------编程问答-------------------- Refer this:
http://www.cnblogs.com/insus/archive/2009/02/28/1400266.html
补充:.NET技术 , ASP.NET