Search in sources :

Example 1 with SimpleWriterExporterOutput

use of net.sf.jasperreports.export.SimpleWriterExporterOutput 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 SimpleWriterExporterOutput

use of net.sf.jasperreports.export.SimpleWriterExporterOutput 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 3 with SimpleWriterExporterOutput

use of net.sf.jasperreports.export.SimpleWriterExporterOutput in project midpoint by Evolveum.

the class ReportCreateTaskHandler method generateReport.

private String generateReport(ReportType reportType, JasperPrint jasperPrint) throws JRException {
    String destinationFileName = getDestinationFileName(reportType);
    switch(reportType.getExport()) {
        case PDF:
            JasperExportManager.exportReportToPdfFile(jasperPrint, destinationFileName);
            break;
        case XML:
            JasperExportManager.exportReportToXmlFile(jasperPrint, destinationFileName, true);
            break;
        case XML_EMBED:
            JasperExportManager.exportReportToXmlFile(jasperPrint, destinationFileName, true);
            break;
        case XHTML:
        case HTML:
            JasperExportManager.exportReportToHtmlFile(jasperPrint, destinationFileName);
            break;
        case CSV:
            JRCsvExporter csvExporter = new JRCsvExporter();
            csvExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
            csvExporter.setExporterOutput(new SimpleWriterExporterOutput(destinationFileName));
            csvExporter.exportReport();
            break;
        case RTF:
        case XLS:
        case ODT:
        case ODS:
        case DOCX:
        case XLSX:
        case PPTX:
        case JXL:
            ExporterInput input = new SimpleExporterInput(jasperPrint);
            ExporterOutput output = new SimpleOutputStreamExporterOutput(destinationFileName);
            Exporter exporter = createExporter(reportType.getExport());
            if (exporter == null) {
                break;
            }
            exporter.setExporterInput(input);
            exporter.setExporterOutput(output);
            exporter.exportReport();
            break;
        default:
            break;
    }
    return destinationFileName;
}
Also used : SimpleWriterExporterOutput(net.sf.jasperreports.export.SimpleWriterExporterOutput) SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) JRCsvExporter(net.sf.jasperreports.engine.export.JRCsvExporter) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput) SimpleWriterExporterOutput(net.sf.jasperreports.export.SimpleWriterExporterOutput) SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) ExporterOutput(net.sf.jasperreports.export.ExporterOutput) JRPptxExporter(net.sf.jasperreports.engine.export.ooxml.JRPptxExporter) Exporter(net.sf.jasperreports.export.Exporter) JRDocxExporter(net.sf.jasperreports.engine.export.ooxml.JRDocxExporter) JRCsvExporter(net.sf.jasperreports.engine.export.JRCsvExporter) JROdtExporter(net.sf.jasperreports.engine.export.oasis.JROdtExporter) JRXlsExporter(net.sf.jasperreports.engine.export.JRXlsExporter) JRXlsxExporter(net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter) JRRtfExporter(net.sf.jasperreports.engine.export.JRRtfExporter) JROdsExporter(net.sf.jasperreports.engine.export.oasis.JROdsExporter) ExporterInput(net.sf.jasperreports.export.ExporterInput) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput)

Aggregations

JRCsvExporter (net.sf.jasperreports.engine.export.JRCsvExporter)3 SimpleExporterInput (net.sf.jasperreports.export.SimpleExporterInput)3 SimpleWriterExporterOutput (net.sf.jasperreports.export.SimpleWriterExporterOutput)3 JRRtfExporter (net.sf.jasperreports.engine.export.JRRtfExporter)2 JRXlsExporter (net.sf.jasperreports.engine.export.JRXlsExporter)2 JROdtExporter (net.sf.jasperreports.engine.export.oasis.JROdtExporter)2 JRDocxExporter (net.sf.jasperreports.engine.export.ooxml.JRDocxExporter)2 SimpleOutputStreamExporterOutput (net.sf.jasperreports.export.SimpleOutputStreamExporterOutput)2 File (java.io.File)1 Preferences (java.util.prefs.Preferences)1 FXML (javafx.fxml.FXML)1 FileChooser (javafx.stage.FileChooser)1 InjectFXML (jgnash.uifx.util.InjectFXML)1 JRException (net.sf.jasperreports.engine.JRException)1 JROdsExporter (net.sf.jasperreports.engine.export.oasis.JROdsExporter)1 JRPptxExporter (net.sf.jasperreports.engine.export.ooxml.JRPptxExporter)1 JRXlsxExporter (net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter)1 Exporter (net.sf.jasperreports.export.Exporter)1 ExporterInput (net.sf.jasperreports.export.ExporterInput)1 ExporterOutput (net.sf.jasperreports.export.ExporterOutput)1