use of net.sf.jasperreports.engine.export.ooxml.JRDocxExporter 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:
}
}
}
Aggregations