public async Task <IActionResult> Relatorio(DateTime?dataMin, DateTime?dataMax) { var vm = new relatorioVM(); vm.listChamados = await _buscaService.FindByDateAsync(dataMin, dataMax); return(View(vm)); }
public async Task <ActionResult> ExcelExport(DateTime?dataMin, DateTime maxDate) { var vm = new relatorioVM(); vm.listChamados = await _exportService.FindByDateAsync(dataMin, maxDate); string[] col_names = new string[] { "Data", "Setor", "Solicitante", "Descrição" }; byte[] resultado; using (var package = new ExcelPackage()) { var worksheet = package.Workbook.Worksheets.Add("Atendimento"); for (int i = 0; i < col_names.Length; i++) { worksheet.Cells[1, i + 1].Style.Font.Size = 14; //font da celula worksheet.Cells[1, i + 1].Value = col_names[i]; //valor da celula worksheet.Cells[1, i + 1].Style.Font.Bold = true; } int row = 3; foreach (Chamados item in vm.listChamados) { for (int col = 1; col <= 4; col++) { worksheet.Cells[row, col].Style.Font.Size = 12; } worksheet.Cells[row, 1].Value = item.DataAbertura.ToShortDateString(); worksheet.Cells[row, 2].Value = item.Setor; worksheet.Cells[row, 3].Value = item.Solicitante; worksheet.Cells[row, 4].Value = item.Descricao; row = (row + 1); } resultado = package.GetAsByteArray(); } return(File(resultado, "application/vnd.ms-excel", "relatorio.xls")); }