Response.Clear( );
Response.Buffer = true;
Response.AddHeader( "content-disposition", "attachment;filename=FileName.xls" );
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentType = "application/vnd.ms-excel"; //Excel
System.IO.StringWriter oStringWriter = new System.IO.StringWriter( );
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter( oStringWriter );
GridView gv = new GridView( );
gv.DataSource = ( gvLoanErrors.DataSource );
gv.DataBind( );
gv.RenderControl( oHtmlTextWriter );
Response.Output.Write( oStringWriter.ToString( ) );
Response.Flush( );
Response.End( );
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/vnd.ms-excel;";
//Response.Charset = "";
Page.EnableViewState = false;
string css = "<style type=\"text/css\">table{text-align:center;width:100%;border: solid 1px black;border-collapse: collapse;font-family: 'Arial', 'Helvetica', 'sans-serif', '宋体';font-size: 20px;}</style>";
Repeater Repeater1 = Control as Repeater;
System.IO.StringWriter sw = new System.IO.StringWriter();
Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + FileName + ".xls\"");
Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\" />");
Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"><title>" + FileName + "</title>" + css + "</head><body><center>");
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(Response.Output);
Repeater1.RenderControl(hw);
//Response.Write(sw.ToString().Replace("<br>", "<br style='mso-data-placement:same-cell;'/>"));
Response.Write("</center></body></html>");
Response.End();
标签: Export to Excel System.OutOfMemoryException
摘要:Export to Excel System.OutOfMemoryException