日期:2014-05-18 浏览次数:20845 次
Response.Clear(); Response.Buffer = true; Response.Charset = "UTF-8"; Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls"); Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/ms-excel"; EnableViewState = false; 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); //你要打印的结果集 string StrSQL = ""; StrSQL = this.getStrSQL(); DataSet DS = new DataSet(); DS = Cls_DB_factory._DataSet(StrSQL); gview.DataSource = DS.Tables[0]; gview.DataBind(); gview.RenderControl(oHtmlTextWriter); // this.GridView1.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Response.End();