public ExporterOutput getExporterOutput(OutputStream output) { return new SimpleOutputStreamExporterOutput(output); }
private SimpleOutputStreamExporterOutput simpleOutputStreamExporterOutput(JasperIExporter jasperExporter) { if (jasperExporter.getOutputStream() != null) { return new SimpleOutputStreamExporterOutput(jasperExporter.getOutputStream()); } if (jasperExporter.getOutputFile() != null) { return new SimpleOutputStreamExporterOutput(jasperExporter.getOutputFile()); } if (jasperExporter.getOutputFileName() != null) { return new SimpleOutputStreamExporterOutput(jasperExporter.getOutputFileName()); } return null; }
/** * Export to DOCX * * @return SpecificTemplateExporterBuilderService * @throws JRException JRException exception */ public SpecificTemplateExporterBuilderService toDocx() throws JRException { JRDocxExporter jrDocxExporter = new JRDocxExporter(); jrDocxExporter.setExporterInput(new SimpleExporterInput(this.report)); jrDocxExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new File(getTemplatePath().replace(extensionPattern, "docx")))); jrDocxExporter.exportReport(); return this; }
/** * Export to ODS * * @return SpecificTemplateExporterBuilderService * @throws JRException JRException exception */ public SpecificTemplateExporterBuilderService toOds() throws JRException { JROdsExporter jrOdsExporter = new JROdsExporter(); jrOdsExporter.setExporterInput(new SimpleExporterInput(this.report)); jrOdsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new File(getTemplatePath().replace(extensionPattern, "ods")))); jrOdsExporter.exportReport(); return this; }
/** * Export to EXCEL * * @return SpecificTemplateExporterBuilderService * @throws JRException JRException exception */ public SpecificTemplateExporterBuilderService toExcel() throws JRException { JRXlsxExporter jrXlsxExporter = new JRXlsxExporter(); jrXlsxExporter.setExporterInput(new SimpleExporterInput(this.report)); jrXlsxExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new File(getTemplatePath().replace(extensionPattern, "xlsx")))); jrXlsxExporter.exportReport(); return this; }
/** * Export to XLS * * @return SpecificTemplateExporterBuilderService * @throws JRException JRException exception */ public SpecificTemplateExporterBuilderService toXls() throws JRException { JRXlsExporter jrXlsExporter = new JRXlsExporter(); jrXlsExporter.setExporterInput(new SimpleExporterInput(this.report)); jrXlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new File(getTemplatePath().replace(extensionPattern, "xls")))); jrXlsExporter.exportReport(); return this; }
/** * Export to XLSX * * @return SpecificTemplateExporterBuilderService * @throws JRException JRException exception */ public SpecificTemplateExporterBuilderService toXlsx() throws JRException { JRXlsxExporter jrXlsxExporter = new JRXlsxExporter(); jrXlsxExporter.setExporterInput(new SimpleExporterInput(this.report)); jrXlsxExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new File(getTemplatePath().replace(extensionPattern, "xls")))); jrXlsxExporter.exportReport(); return this; }
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, SimpleXlsReportConfiguration configuration) throws JRException, FileNotFoundException { JRXlsExporter exporter = new JRXlsExporter(); File outputFile = new File(path); File parentFile = outputFile.getParentFile(); if (parentFile != null) parentFile.mkdirs(); FileOutputStream fos = new FileOutputStream(outputFile); exporter.setConfiguration(configuration); SimpleExporterInput simpleExporterInput = new SimpleExporterInput(jp); OutputStreamExporterOutput simpleOutputStreamExporterOutput = new SimpleOutputStreamExporterOutput(fos); exporter.setExporterInput(simpleExporterInput); exporter.setExporterOutput(simpleOutputStreamExporterOutput); exporter.exportReport(); logger.debug("Xlsx Report exported: " + path); }
/** * The path to the file must exist. * * @param jp * @param path * @throws JRException * @throws FileNotFoundException */ public static void exportReport(JasperPrint jp, String path) throws JRException, FileNotFoundException { logger.debug("Exporing report to: " + path); JRPdfExporter exporter = new JRPdfExporter(); File outputFile = new File(path); File parentFile = outputFile.getParentFile(); if (parentFile != null) parentFile.mkdirs(); FileOutputStream fos = new FileOutputStream(outputFile); SimpleExporterInput simpleExporterInput = new SimpleExporterInput(jp); OutputStreamExporterOutput simpleOutputStreamExporterOutput = new SimpleOutputStreamExporterOutput(fos); exporter.setExporterInput(simpleExporterInput); exporter.setExporterOutput(simpleOutputStreamExporterOutput); exporter.exportReport(); logger.debug("Report exported: " + path); }
@Override public StreamedContent processReport() throws Exception { beforeProcess(); JasperPrint jasperPrint = processaDadosJasper(); if (jasperPrint == null) { JavaScriptUtils.showMessageHeaderWarning(BundleUtils.messageBundle("message.naoExisteDadosImpressao")); return null; } if (typeReport() == FileType.PDF) { File arquivoPdfGeracao = File.createTempFile(fileName(), ".pdf"); InputStream pdfStream = new FileInputStream(arquivoPdfGeracao.getAbsolutePath()); JasperExportManager.exportReportToPdfFile(jasperPrint, arquivoPdfGeracao.getAbsolutePath()); return new DefaultStreamedContent(pdfStream, "application/pdf", fileName() + ".pdf"); } else if (typeReport() == FileType.EXCEL) { File arquivoPdfGeracao = File.createTempFile(fileName(), ".xlsx"); OutputStream outputStream = new FileOutputStream(arquivoPdfGeracao.getAbsolutePath()); JRXlsExporter exporter = new JRXlsExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); configuration.setOnePagePerSheet(true); configuration.setDetectCellType(true); configuration.setCollapseRowSpan(false); exporter.setConfiguration(configuration); exporter.exportReport(); InputStream pdfStream = new FileInputStream(arquivoPdfGeracao.getAbsolutePath()); return new DefaultStreamedContent(pdfStream, FileType.EXCEL.getContentType(), fileName() + ".xlsx"); } return null; }
exporter.setExporterOutput( new SimpleOutputStreamExporterOutput( out ) ); exporter.setConfiguration( config ); exporter.exportReport(); exporter.setExporterOutput( new SimpleOutputStreamExporterOutput( out ) ); exporter.exportReport();
if (ReportOutputType.pdf == outputType) { exporter = new JRPdfExporter(); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); exporter.setConfiguration(new SimplePdfExporterConfiguration()); } else if (ReportOutputType.html == outputType) { } else if (ReportOutputType.docx == outputType){ exporter = new JRDocxExporter(); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); exporter.setConfiguration(new SimpleDocxExporterConfiguration()); } else if (ReportOutputType.xls == outputType){ exporter = new JRXlsExporter(); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); exporter.setConfiguration(new SimpleXlsExporterConfiguration()); } else if (ReportOutputType.xlsx == outputType){ exporter = new JRXlsxExporter(); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); exporter.setConfiguration(new SimpleXlsxExporterConfiguration()); } else
if (ReportOutputType.pdf == outputType) { exporter = new JRPdfExporter(); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); exporter.setConfiguration(new SimplePdfExporterConfiguration()); } else if (ReportOutputType.html == outputType) { } else if (ReportOutputType.docx == outputType){ exporter = new JRDocxExporter(); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); exporter.setConfiguration(new SimpleDocxExporterConfiguration()); } else if (ReportOutputType.xls == outputType){ exporter = new JRXlsExporter(); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); exporter.setConfiguration(new SimpleXlsExporterConfiguration()); } else if (ReportOutputType.xlsx == outputType){ exporter = new JRXlsxExporter(); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream)); exporter.setConfiguration(new SimpleXlsxExporterConfiguration()); } else
ExporterOutput output = writerOutput ? new SimpleWriterExporterOutput(destinationFileName) : new SimpleOutputStreamExporterOutput(destinationFileName);