效果图:
前端页面
Test For Excel
后台页面:TScheduleRExcelDown.aspx.cs
protected void Page_Load(object sender, EventArgs e){ string sqlNode= "/*你的SQL语句*/"; //返回table DataTable dtAll = DBFunction.ExecuteTableSql(sqlNode); DownExcel(dtAll);}////// 下载Excel档/// /// 数据源public void DownExcel(DataTable dt){ HttpResponse resp = System.Web.HttpContext.Current.Response; resp.Charset = "utf-8"; resp.Clear(); string filename = "在装修店铺表_" + DateTime.Now.ToString("yyyyMMdd"); resp.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls"); resp.ContentEncoding = System.Text.Encoding.UTF8; resp.ContentType = "application/ms-excel"; string style = " " + ""; resp.Write(style); resp.Write("
商场 | 铺位编号 | 装修联系人 | 装修联系电话 | 装修日期 |
---|---|---|---|---|
" + tmpRow["BMarketName"].ToString() + " | " + tmpRow["BStoreCode"].ToString() + "_" + tmpRow["BStoreName"].ToString() + " | " + tmpRow["BContactor"].ToString() + " | " + tmpRow["BContactPhone"].ToString() + " | " + tmpRow["BCreatedTime"].ToString() + " |