分頁Repeater導(dǎo)出數(shù)據(jù)到Excel
1.導(dǎo)出Repeater中的數(shù)據(jù)時,導(dǎo)出的數(shù)據(jù)必須是完整的數(shù)據(jù)塊,例如:完整的table。
2.如果導(dǎo)出的數(shù)字按科學(xué)計數(shù)法顯示則在那列加入樣式:style=”vnd.ms-excel.numberformat:@”即可。
3.Repeater導(dǎo)出到Excel的代碼(C#):
public static void ReportToExcel(System.Web.UI.Control ctl) { HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Charset = "gb2312"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("Hello.xls", System.Text.Encoding.UTF8).ToString()); StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); ctl.RenderControl(htw); HttpContext.Current.Response.Write(sw.ToString()); HttpContext.Current.Response.End(); }4.如果支持分頁,并且頁面不是回發(fā)的情況下,可以用如下方法調(diào)用:
string where = string.Format("{0} and PayState=1", whereSQL);//根據(jù)需要,重新拼寫where條件 DataTable dt = Function.PayDesigner.GetPayDesignerList(where, orderSQL, 1, recordCount); //recordCount為記錄的總條數(shù) Repeater1.DataSource = dt; Repeater1.DataBind(); ReportToExcel(Repeater1);新聞熱點
疑難解答