// public ActionResult SaleListByDay(SaleListByDayAction CommandAction) { var result = CommandAction.Execute(); ViewBag.Total = result.Sum(x => Convert.ToInt32(x.Total)); this.ViewBag.Result = result; return(View()); }
// public void ExportExcel1(SaleListByDayAction CommandAction) { this.ViewBag.Result = CommandAction.Execute(); ExcelPackage pck = new ExcelPackage(); ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Report"); ws.Cells["A1"].Value = "Title"; ws.Cells["B1"].Value = "Title"; ws.Cells["A2"].Value = "Table"; ws.Cells["B2"].Value = "Sale"; ws.Cells["A3"].Value = "Date"; ws.Cells["B3"].Value = string.Format("{0:dd MMM yyyy} at {0:H: mm tt};", DateTimeOffset.Now); ws.Cells["A6"].Value = "Mã"; ws.Cells["B6"].Value = "Ngày"; ws.Cells["C6"].Value = "Khách hàng"; ws.Cells["D6"].Value = "Nhân viên bán hàng"; ws.Cells["E6"].Value = "Số lượng"; ws.Cells["F6"].Value = "Tổng tiền"; ws.Cells["G6"].Value = "Tổng doanh thu trong ngày"; int rowStart = 7; foreach (var item in this.ViewBag.Result) { ws.Cells[string.Format("A{0}", rowStart)].Value = item.SaleId; ws.Cells[string.Format("B{0}", rowStart)].Value = Convert.ToDateTime(item.SaleDate).ToString("dd/MM/yyyy"); ws.Cells[string.Format("C{0}", rowStart)].Value = item.CustomerName; ws.Cells[string.Format("D{0}", rowStart)].Value = item.EmployeeName; ws.Cells[string.Format("E{0}", rowStart)].Value = Convert.ToInt32(item.Qty).ToString("#,##0"); ws.Cells[string.Format("F{0}", rowStart)].Value = Convert.ToInt32(item.Total).ToString("#,##0"); //ws.Cells[string.Format("G{0}", rowStart)].Value = Convert.ToInt32(item.ViewBag.Total).ToString("#,##0"); rowStart++; } ws.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment: filename=" + "ExcelReport.xlsx"); Response.BinaryWrite(pck.GetAsByteArray()); Response.End(); }