Exemplo n.º 1
0
        public string WriteToExcel()
        {
            using (var context = new ApplicationContext())
            {
                var query   = GetAll();
                var waiters = waiterController.GetAll();

                string path = Path.Combine(@"C:", "Report.xlsx");

                using (var p = new ExcelPackage())
                {
                    var ws = p.Workbook.Worksheets.Add("Sheet");

                    ws.Cells[1, 1].Value = "Order number";
                    ws.Cells[1, 2].Value = "Order date";
                    ws.Cells[1, 3].Value = "Number table";
                    ws.Cells[1, 4].Value = "Waiter";
                    ws.Cells[1, 5].Value = "Order total price";

                    int i = 2;
                    foreach (var item in query)
                    {
                        ws.Cells[i, 1].Value = item.Id;
                        ws.Cells[i, 2].Value = item.Date.ToString("dd/MM/yyyy");
                        ws.Cells[i, 3].Value = item.NumberTable;
                        ws.Cells[i, 4].Value = waiterFormate(waiters, item.WaiterId);
                        ws.Cells[i, 5].Value = item.TotalPrice;

                        ++i;
                    }

                    for (i = 1; i <= 5; i++)
                    {
                        ws.Column(i).AutoFit();
                    }

                    p.SaveAs(new FileInfo(path));
                }

                return(path);
            }
        }
Exemplo n.º 2
0
 public IList <Waiter> GetAll()
 {
     return(service.GetAll());
 }