public HttpResponseMessage ExportExcelSyntheticByCondition(ParameterExcelByCondition para) { var _ParentUnitCode = _service.GetParentUnitCode(); NvGiaoDichQuayVm.ReportExcel result = null; var unitCode = _service.GetCurrentUnitCode(); para.UnitCode = unitCode; var service = new ProcedureService <NvGiaoDichQuayVm.ReportExcel>(); var data = ProcedureCollection.DuLieuTongHopGiaoDichQuayTheoDieuKien(para.TuNgay, para.DenNgay, para.UnitCode, new BTS.API.ENTITY.ERPContext()); using (ExcelPackage package = new ExcelPackage()) { var ms = new MemoryStream(); package.Workbook.Worksheets.Add("Data"); var worksheet = package.Workbook.Worksheets[1]; int index = 0; worksheet.Cells[1, 1, 1, 5].Merge = true; worksheet.Cells[1, 1].Value = "SIÊU THỊ TỪ SƠN "; worksheet.Cells[2, 1, 2, 5].Merge = true; worksheet.Cells[2, 1].Value = "Đường Lý Thái Tổ, P. Đình Bảng, TX Từ Sơn, Bắc Ninh "; worksheet.Cells[4, 4, 4, 7].Merge = true; worksheet.Cells[4, 4].Value = "BÁO CÁO GIAO DỊCH QUẦY TỔNG HỢP "; worksheet.Cells[5, 4, 5, 8].Merge = true; worksheet.Cells[5, 4].Value = "Từ ngày: " + para.TuNgay.Day + "/" + para.TuNgay.Month + "/" + para.TuNgay.Year + " Đến ngày:" + para.DenNgay.Day + "/" + para.DenNgay.Month + "/" + para.DenNgay.Year; worksheet.Cells[7, 1].Value = "STT"; worksheet.Cells[7, 2].Value = "Mã giao dịch"; worksheet.Cells[7, 3].Value = "Mã giao dịch PK"; worksheet.Cells[7, 4].Value = "Loại giao dịch"; worksheet.Cells[7, 5].Value = "Tổng tiền"; int stt = 1; index = 8; if (data != null && data.Count() >= 1) { var item = data.ToList(); for (int i = 0; i < item.Count; i++) { var hanghoa = new MdMerchandiseVm.Dto(); var innerindex = item[i].MaVatTu; var hanghoatg = _merchandiseservice.UnitOfWork.Repository <MdMerchandise>().DbSet.FirstOrDefault(x => x.MaVatTu == innerindex && x.UnitCode.StartsWith(_ParentUnitCode)); hanghoa = Mapper.Map <MdMerchandise, MdMerchandiseVm.Dto>(hanghoatg); worksheet.Cells[index, 1].Value = stt; worksheet.Cells[index, 2].Value = item[i].MaGiaoDich; worksheet.Cells[index, 3].Value = item[i].MaGiaoDichQuayPK; if (item[i].LoaiGiaoDich == 1) { worksheet.Cells[index, 4].Value = "Bán lẻ"; } else if (item[i].LoaiGiaoDich == 2) { worksheet.Cells[index, 4].Value = "Trả lại"; } worksheet.Cells[index, 5].Value = CurrentSetting.FormatTienViet(item[i].TTienCoVat.ToString()); index++; stt++; } } else { //return null; } package.SaveAs(ms); HttpResponseMessage response = Request.CreateResponse(); response.StatusCode = HttpStatusCode.OK; ms.Seek(0, SeekOrigin.Begin); response.Content = new StreamContent(ms); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline") { FileName = "BaoCaoGiaoDichQuayTongHop.xlsx" }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); return(response); } }