use of net.sf.jasperreports.engine.data.JRMapCollectionDataSource 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.data.JRMapCollectionDataSource 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();
}
}
Aggregations