public static void visualizaJasperEmExcel(String nomeArquivoJasper, List<?> listaDados,
Map<String, Object> parametros) {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
try {
ServletOutputStream streamDeSaida = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachments; filename=\"relatorio.xls\"");
JRDataSource dados = new JRBeanCollectionDataSource(listaDados);
JasperPrint impressoraJasper = JasperFillManager.fillReport(nomeArquivoJasper, parametros, dados);
JRXlsExporter exporter = new JRXlsExporter();
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setWhitePageBackground(true);
configuration.setOnePagePerSheet(true);
exporter.setConfiguration(configuration);
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(streamDeSaida));
exporter.exportReport();
facesContext.responseComplete();
} catch (JRException | IOException e) {
LogUtils.generate(e);
}
}