public HttpResponseMessage ExportExcelDetailsByCondition(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.DuLieuGiaoDichQuayTheoDieuKien(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 "; 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 = "Nhân viên"; worksheet.Cells[7, 3].Value = "Máy bán"; worksheet.Cells[7, 4].Value = "Ngày phát sinh"; worksheet.Cells[7, 5].Value = "Loại giao dịch"; worksheet.Cells[7, 6].Value = "Mã hàng"; worksheet.Cells[7, 7].Value = "Tên hàng"; worksheet.Cells[7, 8].Value = "Số lượng"; worksheet.Cells[7, 9].Value = "Tổng tiền"; index = 8; int stt = 1; 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].MaNguoiTao + "-" + item[i].NguoiTao; worksheet.Cells[index, 3].Value = item[i].MaQuayBan; worksheet.Cells[index, 4].Value = item[i].NgayPhatSinh.Date + "/" + item[i].NgayPhatSinh.Month + "/" + item[i].NgayPhatSinh.Year; worksheet.Cells[index, 6].Value = item[i].MaVatTu; if (hanghoa == null) { worksheet.Cells[index, 7].Value = " "; } worksheet.Cells[index, 7].Value = hanghoa.TenHang; worksheet.Cells[index, 8].Value = item[i].SoLuong; worksheet.Cells[index, 9].Value = CurrentSetting.FormatTienViet(item[i].TTienCoVat.ToString()); if (item[i].LoaiGiaoDich == 1) { worksheet.Cells[index, 5].Value = "xuất bán"; } else if (item[i].LoaiGiaoDich == 2) { worksheet.Cells[index, 5].Value = "bán trả lại"; } 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 = "BaoCaoGiaoDichQuay.xlsx" }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); return(response); } }