public ActionResult test() { List <ItServiceItem> dd = bdb.ItServiceItems.ToList(); DataTable dt = ListToDataTable(dd); OpenXmlExcelHelper.ExportByWeb(dt, "ccc.xls", "aaa"); var json = new { okMsg = "ok" }; return(Json(json, "text/html", JsonRequestBehavior.AllowGet)); }
public ActionResult IsiExportXls(string DealwithpeopleName, string isitype, string sub_isitype, string end_isitype, DateTime?logTimeB, DateTime?logTimeE) { int totalCount; var query = bdb.ItServiceItems.AsQueryable(); List <ItServiceItem> list; totalCount = bdb.ItServiceItems.ToList().Count(); if (!string.IsNullOrWhiteSpace(DealwithpeopleName)) { query = query.Where(i => i.DealwithpeopleName.Contains(DealwithpeopleName.Trim())); totalCount = query.ToList().Count(); } if (!string.IsNullOrWhiteSpace(isitype)) { query = query.Where(i => i.isitype.Contains(isitype)); totalCount = query.ToList().Count(); } if (!string.IsNullOrWhiteSpace(sub_isitype)) { query = query.Where(i => i.sub_isitype.Contains(sub_isitype)); totalCount = query.ToList().Count(); } if (!string.IsNullOrWhiteSpace(end_isitype)) { query = query.Where(i => i.end_isitype.Contains(end_isitype)); totalCount = query.ToList().Count(); } if (!string.IsNullOrWhiteSpace(logTimeB.ToString()) && !string.IsNullOrWhiteSpace(logTimeE.ToString())) { logTimeE = logTimeE.Value.AddDays(1); query = query.Where(i => i.isiCreateDate >= logTimeB && i.isiCreateDate <= logTimeE); //query = query.Where(w => w.logTime.ToString().Contains(logTime)); totalCount = query.ToList().Count(); } list = query.OrderByDescending(c => c.isiCreateDate).ToList(); DataTable dt = new DataTable(); dt.Columns.Add("标题", typeof(string)); dt.Columns.Add("类别", typeof(string)); dt.Columns.Add("申请人", typeof(string)); dt.Columns.Add("申请时间", typeof(string)); dt.Columns.Add("处理人", typeof(string)); dt.Columns.Add("问题描述", typeof(string)); dt.Columns.Add("解决方法", typeof(string)); int k = 0; foreach (var item in list) { DataRow dr = dt.NewRow(); dr["标题"] = item.Title.ToString(); dr["类别"] = GetAllIsiType(item.isitype, item.sub_isitype, item.end_isitype); dr["申请人"] = item.applicant; dr["申请时间"] = item.isiCreateDate.ToString("yyyy/MM/dd hh:mm:ss"); dr["处理人"] = item.DealwithpeopleName; dr["问题描述"] = item.description; dr["解决方法"] = item.solution; dt.Rows.Add(dr); } OpenXmlExcelHelper.ExportByWeb(dt, "result.xls", "result"); var json = new { okMsg = "导出成功" }; return(Json(json, "text/html", JsonRequestBehavior.AllowGet)); }