Search in sources :

Example 1 with SimpleExporterInput

use of net.sf.jasperreports.export.SimpleExporterInput in project opennms by OpenNMS.

the class AbstractMeasurementQueryExecutorTest method createCsv.

protected void createCsv(JasperPrint jasperPrint, String reportName) throws JRException {
    long start = System.currentTimeMillis();
    SimpleExporterInput input = new SimpleExporterInput(jasperPrint);
    SimpleWriterExporterOutput output = new SimpleWriterExporterOutput(createFileName(reportName, "csv"));
    JRCsvExporter exporter = new JRCsvExporter();
    exporter.setExporterInput(input);
    exporter.setExporterOutput(output);
    exporter.exportReport();
    LOG.info("CSV creation time: {} ms", (System.currentTimeMillis() - start));
}
Also used : SimpleWriterExporterOutput(net.sf.jasperreports.export.SimpleWriterExporterOutput) JRCsvExporter(net.sf.jasperreports.engine.export.JRCsvExporter) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput)

Example 2 with SimpleExporterInput

use of net.sf.jasperreports.export.SimpleExporterInput in project archi by archimatetool.

the class JasperReportsExporter method exportDOCX.

void exportDOCX(JasperPrint jasperPrint, File file) throws JRException {
    // System.out.println("Exporting to DOCX: " + file);
    JRDocxExporter exporter = new JRDocxExporter();
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
    exporter.exportReport();
}
Also used : SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput) JRDocxExporter(net.sf.jasperreports.engine.export.ooxml.JRDocxExporter)

Example 3 with SimpleExporterInput

use of net.sf.jasperreports.export.SimpleExporterInput in project jgnash by ccavanaugh.

the class JasperViewerDialogController method handleSaveAction.

@FXML
private void handleSaveAction() {
    Preferences preferences = Preferences.userNodeForPackage(JasperViewerDialogController.class);
    final String lastDir = preferences.get(LAST_DIR, null);
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
    if (lastDir != null) {
        fileChooser.setInitialDirectory(new File(lastDir));
    }
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF Document", "*.pdf", "*.PDF"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("ODT Document", "*.odt", "*.ODT"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("DOCX Document", "*.docx", "*.DOCX"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XLSX Document", "*.xlsx", "*.XLSX"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("CSV Document", "*.csv", "*.CSV"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("RTF Document", "*.rtf", "*.RTF"));
    final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
    if (file != null) {
        preferences.put(LAST_DIR, file.getParent());
        switch(FileUtils.getFileExtension(file.getAbsolutePath()).toLowerCase(Locale.ROOT)) {
            case "pdf":
                try {
                    JasperExportManager.exportReportToPdfFile(jasperPrint.get(), file.getAbsolutePath());
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "odt":
                try {
                    final JROdtExporter exporter = new JROdtExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "docx":
                try {
                    final JRDocxExporter exporter = new JRDocxExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "xlsx":
                try {
                    final JRXlsExporter exporter = new JRXlsExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
                    final SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
                    configuration.setOnePagePerSheet(false);
                    exporter.setConfiguration(configuration);
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "csv":
                try {
                    final JRCsvExporter exporter = new JRCsvExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleWriterExporterOutput(file));
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "rtf":
                try {
                    final JRRtfExporter exporter = new JRRtfExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleWriterExporterOutput(file));
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            default:
        }
    }
}
Also used : SimpleXlsReportConfiguration(net.sf.jasperreports.export.SimpleXlsReportConfiguration) JROdtExporter(net.sf.jasperreports.engine.export.oasis.JROdtExporter) JRException(net.sf.jasperreports.engine.JRException) SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) JRCsvExporter(net.sf.jasperreports.engine.export.JRCsvExporter) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput) JRXlsExporter(net.sf.jasperreports.engine.export.JRXlsExporter) SimpleWriterExporterOutput(net.sf.jasperreports.export.SimpleWriterExporterOutput) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) JRDocxExporter(net.sf.jasperreports.engine.export.ooxml.JRDocxExporter) File(java.io.File) JRRtfExporter(net.sf.jasperreports.engine.export.JRRtfExporter) FXML(javafx.fxml.FXML) InjectFXML(jgnash.uifx.util.InjectFXML)

Example 4 with SimpleExporterInput

use of net.sf.jasperreports.export.SimpleExporterInput in project bamboobsc by billchen198318.

the class JReportUtils method fillReportToResponse.

public static void fillReportToResponse(String reportId, Map<String, Object> paramMap, HttpServletResponse response) throws ServiceException, Exception {
    if (StringUtils.isBlank(reportId)) {
        throw new java.lang.IllegalArgumentException("error, reportId is blank");
    }
    TbSysJreport sysJreport = new TbSysJreport();
    sysJreport.setReportId(reportId);
    DefaultResult<TbSysJreport> result = sysJreportService.findEntityByUK(sysJreport);
    if (result.getValue() == null) {
        throw new ServiceException(result.getSystemMessage().getValue());
    }
    sysJreport = result.getValue();
    String jasperFileFullPath = Constants.getDeployJasperReportDir() + "/" + sysJreport.getReportId() + "/" + sysJreport.getReportId() + ".jasper";
    File jasperFile = new File(jasperFileFullPath);
    if (!jasperFile.exists()) {
        jasperFile = null;
        throw new Exception("error, Files are missing : " + jasperFileFullPath);
    }
    InputStream reportSource = new FileInputStream(jasperFile);
    Connection conn = null;
    try {
        conn = DataUtils.getConnection();
        ServletOutputStream ouputStream = response.getOutputStream();
        JasperPrint jasperPrint = JasperFillManager.fillReport(reportSource, paramMap, conn);
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "inline; filename=" + sysJreport.getReportId() + ".pdf");
        JRPdfExporter jrPdfExporter = new JRPdfExporter();
        jrPdfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
        jrPdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(ouputStream));
        SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
        jrPdfExporter.setConfiguration(configuration);
        configuration.setOwnerPassword(Constants.getEncryptorKey1());
        jrPdfExporter.exportReport();
        ouputStream.flush();
        ouputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DataUtils.doReleaseConnection(conn);
        if (null != reportSource) {
            try {
                reportSource.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        reportSource = null;
        jasperFile = null;
    }
}
Also used : TbSysJreport(com.netsteadfast.greenstep.po.hbm.TbSysJreport) ServletOutputStream(javax.servlet.ServletOutputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Connection(java.sql.Connection) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput) JRPdfExporter(net.sf.jasperreports.engine.export.JRPdfExporter) IOException(java.io.IOException) JRException(net.sf.jasperreports.engine.JRException) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) FileInputStream(java.io.FileInputStream) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SimplePdfExporterConfiguration(net.sf.jasperreports.export.SimplePdfExporterConfiguration) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File)

Example 5 with SimpleExporterInput

use of net.sf.jasperreports.export.SimpleExporterInput in project tutorials by eugenp.

the class SimpleReportExporter method exportToCsv.

public void exportToCsv(String fileName) {
    JRCsvExporter exporter = new JRCsvExporter();
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporter.setExporterOutput(new SimpleWriterExporterOutput(fileName));
    try {
        exporter.exportReport();
    } catch (JRException ex) {
        Logger.getLogger(SimpleReportFiller.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : SimpleWriterExporterOutput(net.sf.jasperreports.export.SimpleWriterExporterOutput) JRException(net.sf.jasperreports.engine.JRException) JRCsvExporter(net.sf.jasperreports.engine.export.JRCsvExporter) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput)

Aggregations

SimpleExporterInput (net.sf.jasperreports.export.SimpleExporterInput)17 SimpleOutputStreamExporterOutput (net.sf.jasperreports.export.SimpleOutputStreamExporterOutput)12 JRException (net.sf.jasperreports.engine.JRException)7 JRXlsExporter (net.sf.jasperreports.engine.export.JRXlsExporter)6 SimpleWriterExporterOutput (net.sf.jasperreports.export.SimpleWriterExporterOutput)5 SimpleXlsReportConfiguration (net.sf.jasperreports.export.SimpleXlsReportConfiguration)5 JasperPrint (net.sf.jasperreports.engine.JasperPrint)4 JRCsvExporter (net.sf.jasperreports.engine.export.JRCsvExporter)4 FileOutputStream (java.io.FileOutputStream)3 HashMap (java.util.HashMap)3 JasperReport (net.sf.jasperreports.engine.JasperReport)3 JRPdfExporter (net.sf.jasperreports.engine.export.JRPdfExporter)3 JRRtfExporter (net.sf.jasperreports.engine.export.JRRtfExporter)3 JROdtExporter (net.sf.jasperreports.engine.export.oasis.JROdtExporter)3 JRDocxExporter (net.sf.jasperreports.engine.export.ooxml.JRDocxExporter)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 JRMapCollectionDataSource (net.sf.jasperreports.engine.data.JRMapCollectionDataSource)2 JRPptxExporter (net.sf.jasperreports.engine.export.ooxml.JRPptxExporter)2