日期:2014-05-20 浏览次数:20986 次
protected void Excel_Click(object sender, EventArgs e) { Response.Clear(); //获取或设置一个值,该值指示是否缓冲输出,并在完成处理整个响应之后将其发送 Response.Buffer = true; //获取或设置输出流的HTTP字符集 Response.Charset = "GB2312"; //将HTTP头添加到输出流 Response.AppendHeader("Content-Disposition", "attachment;filename=PriceManage" + DateTime.Now.Date.ToString("yyyyMMdd") + ".xls"); //获取或设置输出流的HTTP字符集 Response.ContentEncoding = System.Text.Encoding.UTF7; //获取或设置输出流的HTTP MIME类型 Response.ContentType = "application/ms-excel"; System.IO.StringWriter onstringwriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter onhtmltextwriter = new System.Web.UI.HtmlTextWriter(onstringwriter); StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); this.Repeater1.RenderControl(htw); string html = sw.ToString().Trim(); Response.Output.Write(html); Response.Flush(); Response.End(); } public override void VerifyRenderingInServerForm(Control control) { //base.VerifyRenderingInServerForm(control); }
------解决方案--------------------