public ActionResult ExportExcel() { try { var webRoot = _env.WebRootPath; DataTable dt = new DataTable(); QuanLyCongVanContext db = new QuanLyCongVanContext(); var paht = System.IO.Path.Combine(webRoot, "Content/TempExcel/VanBan.xlsx"); Workbook wb = new Workbook(); //Cell Cells = char.Parse(new Cell["A3"].ToString()); Worksheet ws = wb.Worksheets[0]; dt.Columns.Add("Văn bản đi đến"); dt.Columns.Add("Mã loại VB");; dt.Columns.Add("Mã CQBH"); dt.Columns.Add("Số VB"); dt.Columns.Add("Số đến"); dt.Columns.Add("Ngày đến"); dt.Columns.Add("Độ mật"); dt.Columns.Add("Độ khẩn"); dt.Columns.Add("Số đến"); dt.Columns.Add("Trích yếu"); dt.Columns.Add("Nơi nhận"); dt.Columns.Add("Ngày ký"); dt.Columns.Add("Người ký"); dt.Columns.Add("Kết quả xử lý"); dt.Columns.Add("File đính kèm"); List <VanBan> listvb = new List <VanBan>(); listvb = db.VanBan.ToList(); string listvbs = ""; if (listvb.Count > 0) { listvbs = String.Join(",", listvb.Select(x => x.ToString()).ToArray()); } var ob = new VanBanRepository(); var data = ob.GetAll(); foreach (VanBan item in data) { dt.Rows.Add(item.VbdiDen, item.MaLoaiVb, item.MaCqbh, item.SoVb, item.SoDen, Convert.ToDateTime(item.NgayDen), item.DoMat, item.DoKhan, item.TrichYeu, item.NoiNhan, Convert.ToDateTime(item.NgayKy), item.NguoiKy, item.KetQuaXuLy, item.FileDinhKem); } string filename = "DanhSachVanBan" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".xlsx"; string folderName = "/assets/Excel/"; var file = System.IO.Path.Combine(webRoot + folderName + filename); if (!System.IO.Directory.Exists(folderName)) { System.IO.Directory.CreateDirectory(folderName); } ws.Cells.ImportDataTable(dt, false, 2, 0); wb.Save(file); return(Json(folderName + filename)); } catch (Exception ex) { throw ex; } }
private IPagedList <VanBanResult> Find(ValueSearchViewModel model) { var seachAll = VanBanRepository.GetAll(); //if (model.CoQuanBanHanhVanBanId.HasValue) // seachAll = seachAll.Where(x => x.CoQuanBanHanhId == model.CoQuanBanHanhVanBanId); //if (model.LoaiVanBanId.HasValue) // seachAll = seachAll.Where(x => x.LoaiVanBanId == model.LoaiVanBanId); //if (model.LinhVucVanBanId.HasValue) // seachAll = seachAll.Where(x => x.LinhVucVanBanId == model.LinhVucVanBanId); //if (model.NamBanHanhId.HasValue) // seachAll = seachAll.Where(x => x.NgayBanHanh.Year == model.NamBanHanhId); if (model.CoQuanBanHanhVanBanIds != null && model.CoQuanBanHanhVanBanIds.Any()) { seachAll = seachAll.Where(x => model.CoQuanBanHanhVanBanIds.Any(y => y == x.CoQuanBanHanhId)); } if (model.LoaiVanBanIds != null && model.LoaiVanBanIds.Any()) { seachAll = seachAll.Where(x => model.LoaiVanBanIds.Any(y => y == x.LoaiVanBanId)); } if (model.LinhVucVanBanIds != null && model.LinhVucVanBanIds.Any()) { seachAll = seachAll.Where(x => model.LinhVucVanBanIds.Any(y => y == x.LinhVucVanBanId)); } if (model.NamBanHanhIds != null && model.NamBanHanhIds.Any()) { seachAll = seachAll.Where(x => model.NamBanHanhIds.Any(y => y == x.NgayBanHanh.Year)); } if (!string.IsNullOrEmpty(model.TenVanBan)) { if (model.TimTrongNoiDung) { seachAll = seachAll.Where(x => x.NoiDung.Contains(model.TenVanBan)); } if (model.TimTrongSoHieu) { seachAll = seachAll.Where(x => x.SoVanBan.Contains(model.TenVanBan)); } if (model.TimTrongTrichYeu) { seachAll = seachAll.Where(x => x.TrichYeu.Contains(model.TenVanBan)); } } return(seachAll.ToPagedList(model.Page, TechOfficeConfig.PAGESIZE)); }
public ActionResult Index() { var listVanBan = vanbanRepo.GetAll(); return(View(listVanBan)); }