DataTable dt= GetTaskList(int.MaxValue);app
StringBuilder table = new StringBuilder();ui
table.Append("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=UTF-8\"/>"); spa
//在拼接table時,須要加入這句,不然會出現亂碼excel
table.Append("<table cellpadding='1' cellspacing='1' style='width:1200px; background:#CCCCCC;font-size:13px;'>");code
table.Append("<tr>");orm
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>酒店ID</td>");ci
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>酒店名稱</td>");string
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>檢查人</td>");it
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>開始日期</td>");io
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>結束日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>自查日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>整改日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>複覈日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>類型</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>狀態</td>");
table.Append("</tr>");
foreach (DataRow dr in dt.Rows)
{
table.Append("<tr>");
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["HotelID"]);
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["HotelName"]);
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["CheckUser"]);
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["BeginDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["EndDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["CheckSumbitDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["RectifySumbitDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["ReviewSumbitDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["TaskFrom"]);
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["TaskStatus"]);
table.Append("</tr>");
}
table.Append("</table>");
string filename = DateTime.Now.ToString("yyyyMMddHHmmss")+".xls";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + "\"");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel;";
HttpContext.Current.Response.Write(table.ToString());
HttpContext.Current.Response.End();