简体   繁体   English

如何在jasper报告中显示导出的xml?

[英]How to show exported xml in jasper report?

We recently integrated jasper report to our system. 我们最近将碧玉报告集成到了系统中。 Now we can run report and show result to users with jasper report via standard way, run and show result to user. 现在我们可以通过标准方式使用jasper报告运行报告并将结果显示给用户,然后将结果运行并显示给用户。

But in some cases we need to save result to an object storage and show user when requested, as a document. 但是在某些情况下,我们需要将结果保存到对象存储中,并在请求时向用户显示为文档。 As far as I know JasperPrint is a serialized object. 据我所知JasperPrint是一个序列化的对象。 saving report result to object storage as a serialized object is not a good way as we experienced our prior report tool. 将报告结果作为序列化的对象保存到对象存储中不是一个好方法,因为我们经验丰富的先前的报告工具。 if the object changed the serialization mechanism could not deserialize object. 如果对象更改,则序列化机制无法反序列化对象。

So we want to save jasper result in xml format to object storage but we couldn't find any way to show exported xml in JRViewer . 因此,我们希望将jasper结果以xml格式保存到对象存储中,但找不到任何方法可以在JRViewer显示导出的xml。

Is there any way to convert exported xml to a visual form? 有什么方法可以将导出的xml转换为可视形式?

Jasper Report provides two method's for saving and loading your filled report, JasperPrint (note: excluding export's to other formats as pdf,xls ecc, since it would be very difficult to load and export to another format). Jasper Report提供了两种方法来保存和加载已填充的报告JasperPrint (注意:不包括导出为pdf,xls ecc的其他格式,因为要加载和导出为另一种格式非常困难)。

With courtesy of @Robert Mugattarov , What is the difference between JasperReport formats? 感谢@Robert MugattarovJasperReport格式之间有什么区别?

.jrprint is a serialized JasperPrint object ie an actual report instance ie a template that has been filled with data. .jrprint是一个序列化的JasperPrint对象,即实际报告实例,即已填充数据的模板。 This file can be deserialized back into a JasperPrint object. 可以将该文件反序列化回JasperPrint对象。

.jrpxml is a human readable XML represenatation of a JasperPrint object ie an XML version of a template that has been filled with data. .jrpxml是JasperPrint对象的人类可读XML表示形式,即已填充数据的模板的XML版本。 This file can be unmarshalled back into a JasperPrint object. 该文件可以解组回JasperPrint对象。

Since you do not wish do have a serialized object, the solution that remains is the jrpxml format in . 由于不希望有序列化的对象,因此保留的解决方案是jrpxml格式。

Example of saving and loading to jrpxml . 保存并加载到jrpxml

//Save JasperPrint to jrpxml (xml format)
JRXmlExporter exporter = new JRXmlExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleWriterExporterOutput(new File("myJasperPrint.jrpxml")));
exporter.exportReport();

//Load jrpxml to JasperPrint object
JasperPrint print = JRPrintXmlLoader.load("myJasperPrint.jrpxml");

//To show it in JasperViewer
JRViewer jrv = new JRViewer(print);

If you need to reduce file size I suggest that you zip/unzip the jrpxml file. 如果需要减小文件大小,建议您压缩/解压缩jrpxml文件。

What is a good Java library to zip/unzip files? 有什么好的Java库来压缩/解压缩文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM