use of net.sf.jasperreports.engine.export.JRXlsExporter in project adempiere by adempiere.
the class ZkJRViewer method renderReport.
/***
*
* This method is used for generate report in PDF or XLS based on previewType selection.
*
* @throws Exception
*/
private void renderReport() throws Exception {
Listitem selected = previewType.getSelectedItem();
//
// Place Common code outside the If else block
//
String path = System.getProperty("java.io.tmpdir");
String prefix = makePrefix(jasperPrint.getName());
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Path=" + path + " Prefix=" + prefix);
}
if (selected == null || "PDF".equals(selected.getValue())) {
file = File.createTempFile(prefix, ".pdf", new File(path));
JasperExportManager.exportReportToPdfFile(jasperPrint, file.getAbsolutePath());
media = new AMedia(this.title, "pdf", "application/pdf", file, true);
} else if ("XLS".equals(previewType.getSelectedItem().getValue())) {
file = File.createTempFile(prefix, ".xls", new File(path));
FileOutputStream fos = new FileOutputStream(file);
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, fos);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_FILE, file.getAbsolutePath());
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);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, Boolean.FALSE);
exporterXLS.exportReport();
media = new AMedia(this.title, "xls", "application/vnd.ms-excel", file, true);
} else if ("RTF".equals(previewType.getSelectedItem().getValue())) {
FileOutputStream fos = new FileOutputStream(file);
JRRtfExporter rtfExporter = new JRRtfExporter();
rtfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
rtfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);
rtfExporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
rtfExporter.exportReport();
media = new AMedia(this.title, "doc", "application/vnd.ms-word", file, true);
}
iframe.setContent(media);
}
use of net.sf.jasperreports.engine.export.JRXlsExporter 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:
}
}
}
use of net.sf.jasperreports.engine.export.JRXlsExporter in project java-examples by urvanov-ru.
the class App method main.
public static void main(String[] args) {
try {
JasperReport jasperReport = JasperCompileManager.compileReport(App.class.getResourceAsStream("chart1.jrxml"));
Map<String, Object> parameters = new HashMap<>();
List<Map<String, ?>> data = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("x", Integer.valueOf(1));
map.put("v", Integer.valueOf(2));
map.put("name", "name");
data.add(map);
map = new HashMap<>();
map.put("x", Integer.valueOf(2));
map.put("v", Integer.valueOf(1));
map.put("name", "name");
data.add(map);
map = new HashMap<>();
map.put("x", Integer.valueOf(3));
map.put("v", Integer.valueOf(3));
map.put("name", "name");
data.add(map);
JRMapCollectionDataSource dataSource = new JRMapCollectionDataSource(data);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
try (FileOutputStream baos = new FileOutputStream("chart1.xls")) {
JRXlsExporter xlsExporter = new JRXlsExporter();
xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(false);
xlsExporter.setConfiguration(configuration);
xlsExporter.exportReport();
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.sf.jasperreports.engine.export.JRXlsExporter in project java-examples by urvanov-ru.
the class App method main.
public static void main(String[] args) {
try {
JasperReport jasperReport = JasperCompileManager.compileReport(App.class.getResourceAsStream("chart1.jrxml"));
Map<String, Object> parameters = new HashMap<>();
List<Map<String, ?>> data = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("x", Integer.valueOf(10));
map.put("v", Integer.valueOf(20));
map.put("name", "name");
data.add(map);
map = new HashMap<>();
map.put("x", Integer.valueOf(20));
map.put("v", Integer.valueOf(10));
map.put("name", "name");
data.add(map);
map = new HashMap<>();
map.put("x", Integer.valueOf(30));
map.put("v", Integer.valueOf(30));
map.put("name", "name");
data.add(map);
JRMapCollectionDataSource dataSource = new JRMapCollectionDataSource(data);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
try (FileOutputStream baos = new FileOutputStream("chart1.xls")) {
JRXlsExporter xlsExporter = new JRXlsExporter();
xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(false);
xlsExporter.setConfiguration(configuration);
xlsExporter.exportReport();
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.sf.jasperreports.engine.export.JRXlsExporter in project java-examples by urvanov-ru.
the class App method generateReport.
public static void generateReport() throws JRException, IOException {
JasperDesign jasperDesign = createDesign();
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JRDataSource jrDataSource = prepareDataSource();
Map<String, Object> params = new HashMap<String, Object>();
params.put("startDate", new Date());
params.put("endDate", new Date());
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, jrDataSource);
try (FileOutputStream baos = new FileOutputStream("dynamicReport.xls")) {
JRXlsExporter xlsExporter = new JRXlsExporter();
xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(false);
xlsExporter.setConfiguration(configuration);
xlsExporter.exportReport();
}
}
Aggregations