private FileContentResult GenerateSpecialReport(SpecialReportFilter specialReportFilter) { dynamic data; if (specialReportFilter.ReportType == 1) { data = _specialReportService.GetSpecialSummaryReport(specialReportFilter); } else { data = _specialReportService.GetSpecialDetailedReport(specialReportFilter); } var rootPath = Path.Combine(_hostingEnvironment.WebRootPath, "Temp"); var excelFile = _excelReportService.GenerateExcelReport(rootPath, data.Result); var response = new HttpResponseMessage(HttpStatusCode.OK); var bytes = System.IO.File.ReadAllBytes(excelFile); var fileName = Path.GetFileNameWithoutExtension(excelFile); response.Content = new ByteArrayContent(bytes); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.Content.Headers.ContentDisposition.FileName = fileName + ".xlsx"; return(File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName + ".xlsx")); }
public IActionResult Post([FromBody] PaymentReportFilter paymentReportFilter) { var data = _paymentReportService.GetPaymentReport(paymentReportFilter); var rootPath = Path.Combine(_hostingEnvironment.WebRootPath, "Temp"); var excelFile = _excelReportService.GenerateExcelReport(rootPath, data.Result); var response = new HttpResponseMessage(HttpStatusCode.OK); var bytes = System.IO.File.ReadAllBytes(excelFile); var fileName = Path.GetFileNameWithoutExtension(excelFile); response.Content = new ByteArrayContent(bytes); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.Content.Headers.ContentDisposition.FileName = fileName + ".xlsx"; return(File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName + ".xlsx")); }