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); // configurar o exporter JRXlsExporter exporter = new JRXlsExporter(); // exporter.setParameter(JExcelApiExporterParameter.JASPER_PRINT, impressoraJasper); // exporter.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, streamDeSaida); // exporter.setParameter(JExcelApiExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE); // exporter.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); 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); } }
public static void exportReportXls(JasperPrint jp, String path) throws JRException, FileNotFoundException { SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); configuration.setDetectCellType(true); configuration.setWhitePageBackground(false); configuration.setIgnoreGraphics(false); configuration.setIgnorePageMargins(true); exportReportXls(jp, path, configuration); }
config.setRemoveEmptySpaceBetweenRows( true ); config.setCollapseRowSpan( true ); config.setWhitePageBackground( false );