Пример #1
0
        // GET: Console/ExportReports

        public ActionResult ExportReports()
        {
            IViewerFactory <ReportView> factory = new ReportViewFactory();

            var list = factory.Query(new Criteria(new
            {
                MenuDate = DateTime.Today,
                MenuType = (int)MenuDto.GetMenuLunchOrSupper(0, false)
            }));

            if (list != null && list.Count > 0)
            {
                var mapper  = ReportDto.ConfigMapper().CreateMapper();
                var reports = mapper.Map <IEnumerable <ReportDto> >(list.AsEnumerable()).ToList();

                var book = ExcelManager.BuildReportWorkbook(reports);

                byte[] file;
                using (var ms = new MemoryStream())
                {
                    book.Write(ms);
                    file = ms.GetBuffer();
                }

                return(File(file, "application/vnd.ms-excel", $@"今日订餐统计表-{DateTime.Today:yyyyMMdd}.xls"));
            }


            return(RedirectToAction("Index", "Home"));
        }