public void export(HttpServletRequest req, HttpServletResponse res) throws Exception { String fileName=this.getExportFileName(req); fileName+=".csv"; res.setContentType("application/octet-stream"); res.setHeader("Connection", "close"); res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\""); JRCsvExporter exporter = new JRCsvExporter(DefaultJasperReportsContext.getInstance()); JasperPrint jasperPrint=this.getJasperPrint(req); exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); OutputStream ouputStream = res.getOutputStream(); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); try { exporter.exportReport(); } catch (JRException e) { throw new ServletException(e); } finally { if (ouputStream != null) { ouputStream.flush(); ouputStream.close(); } } }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/CustomersReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); //exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, "|"); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { File[] files = getFiles(new File("build/reports"), "jrprint"); for(int i = 0; i < files.length; i++) { long start = System.currentTimeMillis(); File sourceFile = files[i]; JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("Report : " + sourceFile + ". CSV creation time : " + (System.currentTimeMillis() - start)); } }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/JsonCustomersReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); //exporter.setParameter(JRCsvExporterParameter.FIELD_DELIMITER, "|"); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/ScriptletReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); SimpleCsvReportConfiguration configuration = new SimpleCsvReportConfiguration(); configuration.setProgressMonitor(new SimpleExportProgressMonitor()); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>(); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report1.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report2.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report3.jrprint")); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); exporter.setExporterOutput(new SimpleWriterExporterOutput("build/reports/BatchExportReport.csv")); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
@Override public String getTextValue(JRCsvExporterContext exporterContext, JRGenericPrintElement element) { JRPrintText labelPrintText = (JRPrintText)element.getParameterValue(IconLabelElement.PARAMETER_LABEL_TEXT_ELEMENT); if (labelPrintText == null) { return null; } String text = null; JRStyledText styledText = ((JRCsvExporter)exporterContext.getExporterRef()).getStyledText(labelPrintText); if (styledText == null) { text = ""; } else { text = styledText.getText(); } return text; }
private Exporter createExporter(ExportType type) { switch (type) { case CSV: return new JRCsvExporter(); case RTF: return new JRRtfExporter(); case XLS: return new JRXlsExporter(); case ODT: return new JROdtExporter(); case ODS: return new JROdsExporter(); case DOCX: return new JRDocxExporter(); case XLSX: return new JRXlsxExporter(); case PPTX: return new JRPptxExporter(); default: return null; } }
private void exportPrintObject(ReporterConfig rc, final JasperPrint print, final ComponentExecutionApi reporter) { // build the export filename String filename = buildFilename(reporter, rc); // do each export option if (rc.isCsv()) { export(new JRCsvExporter(), print, filename, "csv", rc.isOpenExportFile()); } if (rc.isDocx()) { export(new JRDocxExporter(), print, filename, "docx", rc.isOpenExportFile()); } if (rc.isOdt()) { export(new JROdtExporter(), print, filename, "odt", rc.isOpenExportFile()); } if (rc.isHtml()) { export(new JRHtmlExporter(), print, filename, "html", rc.isOpenExportFile()); } if (rc.isPdf()) { export(new JRPdfExporter(), print, filename, "pdf", rc.isOpenExportFile()); } if (rc.isXls()) { export(new JRXlsExporter(), print, filename, "xls", rc.isOpenExportFile()); } // do show viewer at the end so it pops up after everything else if (rc.isShowViewer()) { reporter.submitControlLauncher(new ControlLauncherCallback() { @Override public void launchControls(ComponentControlLauncherApi launcherApi) { class DisposableViewer extends JRViewer implements Disposable { DisposableViewer(JasperPrint jrPrint) { super(jrPrint); } @Override public void dispose() { } } DisposableViewer viewer = new DisposableViewer(print); launcherApi.registerPanel("report", null, viewer, true); } }); } }
private void exportToCSV(String delim) { log.debug("exporting to CSV. Delimiter char '" + delim + "'"); csvExporter = new JRCsvExporter(); setExportParameter(JRCsvExporterParameter.FIELD_DELIMITER, delim); setExportParameter(JRCsvExporterParameter.RECORD_DELIMITER, "\r\n"); csvExporter.setParameters(getExportParameters()); try { start = System.currentTimeMillis(); csvExporter.exportReport(); log.info("export running time (msec): " + (System.currentTimeMillis() - start)); } catch (JRException jre) { jre.printStackTrace(); log.error(jre.getCause()); } }
private JRCsvExporter csv(JasperICsvExporter jasperExporter) { SimpleWriterExporterOutput exporterOutput = simpleWriterExporterOutput(jasperExporter); SimpleCsvReportConfiguration reportExportConfiguration = new SimpleCsvReportConfiguration(); reportExportConfiguration(reportExportConfiguration, jasperExporter); SimpleCsvExporterConfiguration exporterConfiguration = new SimpleCsvExporterConfiguration(); if (jasperExporter.getFieldDelimiter() != null) { exporterConfiguration.setFieldDelimiter(jasperExporter.getFieldDelimiter()); } if (jasperExporter.getRecordDelimiter() != null) { exporterConfiguration.setRecordDelimiter(jasperExporter.getRecordDelimiter()); } JRCsvExporter jrExporter = new JRCsvExporter(); jrExporter.setExporterOutput(exporterOutput); jrExporter.setConfiguration(reportExportConfiguration); jrExporter.setConfiguration(exporterConfiguration); return jrExporter; }
public static byte[] getCSV(JasperPrint jasperPrint) throws JRException { byte[] content = null; ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); JRCsvExporter exporter = new JRCsvExporter(); content = getBytes(exporter, baos, jasperPrint); } finally { if (baos != null) { try { baos.flush(); baos.close(); } catch (Exception e) { e.printStackTrace(); } } } return content; }
@Override protected net.sf.jasperreports.engine.JRExporter createExporter() { return new JRCsvExporter(); }
/** * Fills a servletoutout stream with data from a JasperReport * @param jasperPrint JasperPrint * @param sos ServletOutputStream * @throws JRException */ private void exportReportToCSVStream(JasperPrint jasperPrint, OutputStream sos) throws JRException { JRCsvExporter exp = new JRCsvExporter(); exp.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exp.setParameter(JRExporterParameter.OUTPUT_STREAM, sos); exp.exportReport(); }
/** * Generates a CSV report from a pre-compiled report and returns it into an output stream. * * @param jasperPrint * JasperPrint object which contains a compiled report. * @param outputStream * The output stream used to return the report. * @throws JRException * In case there is any error generating the report an exception is thrown with the * error message. */ private static void saveCsvReportToOutputStream(JasperPrint jasperPrint, OutputStream outputStream) throws JRException { final JRCsvExporter csvExporter = new JRCsvExporter(); SimpleExporterInput exporterInput = new SimpleExporterInput(jasperPrint); SimpleWriterExporterOutput exporterOutput = new SimpleWriterExporterOutput(outputStream); csvExporter.setConfiguration(new SimpleCsvReportConfiguration()); csvExporter.setExporterInput(exporterInput); csvExporter.setExporterOutput(exporterOutput); csvExporter.exportReport(); }
private static void exportCsv(JasperPrint jasperPrint) throws JRException { long start = System.currentTimeMillis(); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput("build/reports/" + jasperPrint.getName() + ".csv")); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
@Override public void save(JasperPrint jasperPrint, File file) throws JRException { if (!file.getName().toLowerCase().endsWith(EXTENSION_CSV)) { file = new File(file.getAbsolutePath() + EXTENSION_CSV); } if ( !file.exists() || JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog( null, MessageFormat.format( getBundleString("file.exists"), new Object[]{file.getName()} ), getBundleString("save"), JOptionPane.OK_CANCEL_OPTION ) ) { JRCsvExporter exporter = new JRCsvExporter(getJasperReportsContext()); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(file)); exporter.exportReport(); } }
public void exportCsv() throws JRException { JRCsvExporter exporter = new JRCsvExporter(); SimpleCsvExporterConfiguration configuration = new SimpleCsvExporterConfiguration(); configuration.setFieldDelimiter(config.getOutFieldDel()); exporter.setConfiguration(configuration); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput( this.output.getAbsolutePath() + ".csv", config.getOutCharset())); exporter.exportReport(); }
private static JRExporter getJREXporter(final String extension) { if ("pdf".equalsIgnoreCase(extension)) { JRPdfExporter exporter = new JRPdfExporter(); // exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print();"); return exporter; } else if ("html".equalsIgnoreCase(extension)) { return new JRHtmlExporter(); } else if ("xls".equalsIgnoreCase(extension)) { JRXlsExporter exporterXLS = new JRXlsExporter(); exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); return exporterXLS; } else if ("txt".equalsIgnoreCase(extension)) { return new JRTextExporter(); } else if ("csv".equalsIgnoreCase(extension)) { return new JRCsvExporter(); } else if ("docx".equalsIgnoreCase(extension)) { return new JRDocxExporter(); } return null; }
@Override protected JRCsvExporter getExporter(JasperReportsConfiguration jContext, JRExportProgressMonitor monitor, File file) { JRCsvExporter exp = new JRCsvExporter(jContext); exp.setExporterOutput(new SimpleWriterExporterOutput(file)); SimpleCsvReportConfiguration rconf = new SimpleCsvReportConfiguration(); setupReportConfiguration(rconf, monitor); exp.setConfiguration(rconf); return exp; }
private String saveReport(JasperPrint jasperPrint, Report report, String destFileName) throws JRException, Exception{ createReportCatalogEntry(jasperPrint, report, destFileName); String reportName=null; switch(Format.valueOf(report.getReportFormat())){ case pdf: JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName); reportName = destFileName; break; case html: JasperExportManager.exportReportToHtmlFile(jasperPrint,destFileName); reportName = createZip(destFileName); break; case xml: JasperExportManager.exportReportToXmlFile(jasperPrint,destFileName,true); reportName = createZip(destFileName); break; case csv: JRCsvExporter exporter = new JRCsvExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileName); exporter.exportReport(); reportName = destFileName; break; default: LogUtils.errorf(this, "Error Running Report: Unknown Format: %s", report.getReportFormat()); } return reportName; }
private void exportReportToCsv(JasperPrint jasperPrint, OutputStream outputStream) throws JRException { JRCsvExporter exporter = new JRCsvExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); exporter.exportReport(); }
@Override public void export(JasperPrint jasper_print, OutputStream stream, SimpleReportExportConfiguration config, Map<String, byte[]> images) throws JRException { JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasper_print)); exporter.setConfiguration((CsvReportConfiguration) config); SimpleWriterExporterOutput output = new SimpleWriterExporterOutput(stream); exporter.setExporterOutput(output); exporter.exportReport(); }
private String saveReport(JasperPrint jasperPrint, String format, String destFileName) throws JRException, Exception{ String reportName=null; switch(Format.valueOf(format)){ case pdf: JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName); reportName = destFileName; break; case html: JasperExportManager.exportReportToHtmlFile(jasperPrint,destFileName); reportName = createZip(destFileName); break; case xml: JasperExportManager.exportReportToXmlFile(jasperPrint,destFileName,true); reportName = createZip(destFileName); break; case csv: JRCsvExporter exporter = new JRCsvExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFileName); exporter.exportReport(); reportName = destFileName; break; default: LogUtils.errorf(this, "Error Running Report: Unknown Format: %s",format); } return reportName; }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/UnicodeReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile, "UTF-8")); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/BookReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/Barcode4JReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/DataSourceReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/FontsReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/FormsReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/StyledTextReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/MapReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/TabularReport.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }
/** * */ public void csv() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/XYChart.jrprint"); JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("CSV creation time : " + (System.currentTimeMillis() - start)); }