public async Task <IActionResult> BookingsCompletions([FromQuery] DateTime?startTime, [FromQuery] DateTime?endTime, [FromQuery] string interval, [FromQuery] int[] rID) { DateTime start = startTime ?? DateTime.Now.AddDays(-7); DateTime end = endTime ?? DateTime.Now; BookingsStats stats = await statisticsService.GetBookingsCompletions(start, end, interval, rID); BookingStatsDTO dto = dtoMapper.Map <BookingStatsDTO>(stats); return(Ok(dto)); }
public async Task <IActionResult> BookingsCancellationsDownload([FromQuery] DateTime?startTime, [FromQuery] DateTime?endTime, [FromQuery] string interval, [FromQuery] int[] rID) { DateTime start = startTime ?? DateTime.Now.AddDays(-7); DateTime end = endTime ?? DateTime.Now; BookingsStats stats = await statisticsService.GetBookingsCompletions(start, end, interval, rID); var memory = await excelService.CreateAndSaveExcelFile(stats); return(File(memory, GetContentType("../../file.xls"), "../../file.xls")); }
public async Task <MemoryStream> CreateAndSaveExcelFile(BookingsStats bookingsStats) { //Initialize ExcelEngine. using (ExcelEngine excelEngine = new ExcelEngine()) { //Initialize Application. IApplication application = excelEngine.Excel; //Set default version for application. application.DefaultVersion = ExcelVersion.Excel2013; //Create a new workbook. IWorkbook workbook = application.Workbooks.Create(1); //Accessing first worksheet in the workbook. IWorksheet worksheet = workbook.Worksheets[0]; //Adding text to a cell worksheet.Range["A1"].Text = bookingsStats.Type; worksheet.Range["A3"].Text = "Дата"; worksheet.Range["B3"].Text = "Кількість бронювань"; int count = 4; for (int i = 0; i < bookingsStats.BookingsAll.Length; i++) { worksheet.Range["A" + count].Text = bookingsStats.IntervalsValues[i].ToString(); worksheet.Range["B" + count].Text = bookingsStats.BookingsAll[i].ToString(); count++; } //Saving the Excel to the MemoryStream MemoryStream memory = new MemoryStream(); using (var fileStream = File.Create("../../file.xlsx")) { workbook.SaveAs(memory); } memory.Position = 0; return(memory); } }