public void ProcessRequest(HttpContext context) { string s = context.Request["json"]; DataTable dt = new SrnprWeb.WebProcess.GridShowWWP().GetDataTable(s,0); HttpResponse resp; resp = context.Response; resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); resp.AppendHeader("Content-Disposition", "attachment;filename=" + "11.xsls"); int iColumnCount = dt.Columns.Count; StringBuilder sb = new StringBuilder(); foreach (DataRow dr in dt.Rows) { List<string> lStr = new List<string>(); for (int i = 0; i < iColumnCount; i++) { lStr.Add(dr[i].ToString().Trim()); } sb.Append(string.Join("\t", lStr.ToArray()) + "\n"); } resp.Write(sb.ToString()); //写缓冲区中的数据到HTTP头文件中 resp.End(); }
protected void btnExcelAll_Click(object sender, EventArgs e) { string s = hfJson.Value.Trim(); DataTable dt = new SrnprWeb.WebProcess.GridShowWWP().GetDataTable(s, 1); DataTableToExcel(dt, DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")+ ".xls"); }