DataTable dt = ViewState["DtDatat"] as DataTable; //Repeater绑定的数据源 this.Repeater1.DataSource = dt; this.Repeater1.DataBind(); DisplayDetailCol(false); //使用流方式导出Excel HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Charset = "gb2312"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Context.Server.UrlPathEncode("excel名称.xls")); //解决中文乱码问题 StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); Repeater1.RenderControl(htw); HttpContext.Current.Response.Write(sw.ToString()); HttpContext.Current.Response.End();
DataTable dt = ViewState["DtDatat"] as DataTable; //Repeater绑定的数据源 this.Repeater1.DataSource = dt; this.Repeater1.DataBind(); DisplayDetailCol(false); //使用流方式导出Excel HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Charset = "gb2312"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Context.Server.UrlPathEncode("excel名称.xls")); //解决中文乱码问题 StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); Repeater1.RenderControl(htw); HttpContext.Current.Response.Write(sw.ToString()); HttpContext.Current.Response.End();