Reputation: 11
I make reports using Jasper Soft - I make tables, generate jrxml, calculate data and fill in this template.
public static void exportToOds(List<JasperPrint> jasperPrints, ByteArrayOutputStream output) {
try (ByteArrayOutputStream outputStream = output) {
JROdsExporter exporter = new JROdsExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrints));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
SimpleOdsReportConfiguration configuration = new SimpleOdsReportConfiguration();
configuration.setOnePagePerSheet(true);
exporter.setConfiguration(configuration);
exporter.exportReport();
} catch (Exception e) {
throw new RuntimeException("Error exporting report to ODS", e);
}
}
public void fill(UUID templateId, List<JasperPrint> jasperPrints, StorageMtsData data) {
List<StorageMtsDataSheet> sheet = data.getStorageMtsDataSheet();
JasperReport jasperReport = compileReport(String.format("report/%s/StorageMTCMainReport.jrxml", templateId));
JasperReport jasperSubReport = compileReport(String.format("report/%s/StorageMTCSubReport.jrxml", templateId));
JasperReport jasperSubSubReport = compileReport(String.format(
"report/%s/StorageMTCSubSubTAReport.jrxml",
templateId
));
JRBeanCollectionDataSource mainDataSource = new JRBeanCollectionDataSource(sheet);
Map<String, Object> params = new HashMap<>();
params.put("SUBREPORT_PATH", jasperSubReport);
params.put("SUBREPORT_SUBREPORT_PATH", jasperSubSubReport);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, mainDataSource);
jasperPrints.add(jasperPrint);
}
}
The fact is that when you open the ODS file using OpenOffice or LibraOfiice, all the tables are filled, and if you open them using MicrosoftExcel, only empty tables. If you open it using OpenOffice or LibraOfiice and save it, then after that, when you open it using Excel, all the data is there. Compared the file before saving and after saving - the manifest version is changing: before saving - 1.0, after saving - 1.3. I need to make the generated ODS file open immediately using Excel without intermediate saves.
Upvotes: 0
Views: 55