Beispiel #1
0
        //ham bao cao tong doanh thu
        public void RevenueByMonth(string Start, string End, string CustomerId, string CustomerName)
        {
            DateTime     start    = DateTime.ParseExact(Start + " 00:00", "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
            DateTime     end      = DateTime.ParseExact(End + " 23:59", "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
            FileInfo     template = new FileInfo(HostingEnvironment.MapPath("~/Content/template2.xlsx"));
            ExcelPackage EP       = new ExcelPackage(template);

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            ExcelWorksheet Sheet = EP.Workbook.Worksheets[0];

            Sheet.Cells[string.Format("B3")].Value = "Từ " + Start + " - " + End + " - " + CustomerName;
            int id = Int32.Parse(CustomerId);
            List <VT_RevenueByMonth_Result> list = db.VT_RevenueByMonth(start, end, id).ToList();
            int row = 6;

            foreach (var item in list)
            {
                Sheet.Cells[string.Format("B{0}", row)].Value = row - 5;
                Sheet.Cells[string.Format("C{0}", row)].Value = item.CreateDate;
                Sheet.Cells[string.Format("D{0}", row)].Value = item.Type;
                Sheet.Cells[string.Format("E{0}", row)].Value = item.Booking;
                Sheet.Cells[string.Format("F{0}", row)].Value = getFullName(item.FeeName);
                Sheet.Cells[string.Format("G{0}", row)].Value = item.Unit;
                Sheet.Cells[string.Format("H{0}", row)].Value = item.Quantity;
                Sheet.Cells[string.Format("I{0}", row)].Value = item.FeeAmount;
                Sheet.Cells[string.Format("J{0}", row)].Value = item.Total;
                row++;
            }
            Response.Clear();
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.AddHeader("content-disposition", "attachment: filename=" + "Report.xlsx");
            Response.BinaryWrite(EP.GetAsByteArray());
            Response.End();
        }