1.導出Repeater中的數據時,導出的數據必須是完整的數據塊,例如:完整的table。
2.如果導出的數字按科學計數法顯示則在那列加入樣式:style=”vnd.ms-excel.numberformat:@”即可。
3.Repeater導出到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.如果支持分頁,并且頁面不是回發的情況下,可以用如下方法調用:
string where = string.Format("{0} and PayState=1", whereSQL);//根據需要,重新拼寫where條件 DataTable dt = Function.PayDesigner.GetPayDesignerList(where, orderSQL, 1, recordCount); //recordCount為記錄的總條數 Repeater1.DataSource = dt; Repeater1.DataBind(); ReportToExcel(Repeater1);新聞熱點
疑難解答