ASP.NET导出Excel

this.tblMyReport.GridLines = GridLines.Both;

            Response.Clear();

            Response.Buffer = true;

            Response.Charset = "GB2312";

            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");   

            Response.ContentType = "application/ms-excel";   

            this.EnableViewState = false;

            Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");

            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("zh-cn", true);

            System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);

            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

            this.tblMyReport.RenderControl(oHtmlTextWriter);

            Response.Write(oStringWriter.ToString());

            this.tblMyReport.GridLines = GridLines.None;

            Response.End();

posted @ 2013-10-15 22:23  源起  阅读(136)  评论(0)    收藏  举报