Export to Excel System.OutOfMemoryException
Posted By:佳馨科技 Date:2014/3/13 20:57:32 最后修改:2014/3/13 20:57:32 Click Rate:363

                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


收录查询 Copyright ? 2024  广西佳馨科技   地址:广西佳馨科技  电话:13878876479   QQ:120947546  电子邮件:1447876499@qq.com   站点提供API   桂ICP备14003626号-1
关闭 X