62,074
社区成员
发帖
与我相关
我的任务
分享
private void repeaterToExecl(Repeater r)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "inline;filename=test.xls");
Response.Charset = "GB2312";
Response.ContentEncoding = Encoding.UTF8;
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
Page.EnableViewState = false;
r.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
this.Repeater1.RenderControl(hw);
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Page.EnableViewState = false;
Response.AppendHeader("Content-Disposition", "attachment;filename=Teacher.xls");
Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"><title> Copyright by SDU</title></head><body><center>");
Response.Write(sw.ToString());
Response.Write("</center></body></html>");
Response.End();
//当字符型的数字串导出到excel的时候,经常自动变为科学记数法表示,解决的方法,绑定到Repeater1的时候如此:
//<td style="vnd.ms-excel.numberformat:@"><%# DataBinder.Eval(Container.DataItem, "shenfenzheng") %></td>