在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
把Datatable导出为Excel protected void ExportDataTableToExcel(DataTable dt, string ExcelFileName) string attachment = "attachment; filename=" + ExcelFileName + ".xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/vnd.ms-excel"; string tab = ""; foreach (DataColumn dc in dt.Columns) Response.Write(tab + dc.ColumnName); tab = "\t"; } Response.Write("\n"); int i; foreach (DataRow dr in dt.Rows) tab = ""; for (i = 0; i < dt.Columns.Count; i++) Response.Write(tab + dr[i].ToString()); tab = "\t"; } Response.Write("\n"); } Response.End(); }
--------------------- DataTable dt = new DataTable(); sda.Fill(dt); foreach (DataColumn c in dt.Columns) ----------------------------------- |
请发表评论