日期:2014-05-18  浏览次数:20402 次

GridView大数据量导入Excel报错
大数据量导出时报System.OutOfMemory Exception错误 网上查了下是内存不足 看了很多帖子都没有说真正能解决的办法 以下是我的代码
Dim style As String = "<style>td{mso-number-format:""\@"";}</style>"
  Dtg_Mst.GridLines = GridLines.Both
  Dtg_Mst.BorderWidth = 1
  Dim i As Integer
  For i = 0 To Dtg_Mst.Columns.Count - 1
  If Dtg_Mst.Columns(i).GetType().Equals(GetType(CommandField)) Or Dtg_Mst.Columns(i).GetTyp
().Equals(GetType(ButtonField)) Then
  Dtg_Mst.Columns(i).Visible = False
  End If
  Next
  PrepareForExcel(Dtg_Mst)
  page.Response.Clear()
  page.Response.Charset = "GB2312"
  page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
  page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename + ".xls", Encoding.UTF8).ToString())
  page.Response.ContentType = "application/ms-excel"
  page.EnableViewState = False
  Dtg_Mst.AllowPaging = False
  Dim myCItrad As New System.Globalization.CultureInfo("ZH-CN", True)
  Dim sw As New StringWriter()
  Dim htw As New HtmlTextWriter(sw)
  Dtg_Mst.RenderControl(htw)
  page.Response.Write(style)
  page.Response.Write(sw.ToString())
  page.Response.End()
谁能给一个真正有效的解决办法 谢谢

------解决方案--------------------
还有就是你不要用gridview导出,重新查询用datareader导出,然后导出分多个工作簿