java 如何使用 Jasper Report 生成 doc 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29889700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:05:20  来源:igfitidea点击:

How to generate a doc file using Jasper Report

javajasper-reportsdoc

提问by Hmahwish

Using jasper-reports 5.6.1 I am able to generate the reports in pdf format, but I am not able figure out how to generate a .doc format by using jasper.

使用 jasper-reports 5.6.1 我能够生成 pdf 格式的报告,但我无法弄清楚如何使用 jasper 生成 .doc 格式。

      byte[] exportReportToPdf = JasperExportManager.exportReportToPdf(print);

is for generating a pdf format file like this is there any similar view class for doc format?

用于生成这样的pdf格式文件 是否有类似的doc格式视图类?

回答by sanBez

Try like this

像这样尝试

JasperPrint jasperPrint = JasperFillManager.fillReport("myReport.jasper", reportParameters, dataSource);

Exporter exporter = new JRDocxExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));

File exportReportFile = new File("D:\Temp\report.docx");

exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(exportReportFile));

exporter.exportReport();

HTH

HTH

回答by karvin.developer

Before executing a report, the JRXML must be compiled in a binary object called a Jasper file(*.jasper). This compilation is done for performance reasons. Jasper files are what you need to ship with your application in order to run the reports. Once the report is compiled it is filled with data from the application. The class net.sf.jasperreports.engine.JasperFillManager provides necessary functions to fill the data in the reports.

在执行报告之前,JRXML 必须在称为 Jasper 文件 (*.jasper) 的二进制对象中进行编译。出于性能原因进行此编译。Jasper 文件是您需要随应用程序一起提供以运行报告的文件。一旦报告被编译,它就会填充来自应用程序的数据。类 net.sf.jasperreports.engine.JasperFillManager 提供必要的函数来填充报告中的数据。

The report execution is performed by passing a Jasper file and a data source to JasperReports. There are plenty of types of data sources, it's possible to fill a Jasper file from an SQL query, an XML file, a csv file, an HQL (Hibernate Query Language) query, a collection of Java Beans, etc... If you don't find a suitable data source, JasperReports is very flexible and allows you to write your own custom data source.

报告执行是通过将 Jasper 文件和数据源传递给 JasperReports 来执行的。有很多类型的数据源,可以从 SQL 查询、XML 文件、csv 文件、HQL(Hibernate 查询语言)查询、Java Bean 集合等填充 Jasper 文件……如果你找不到合适的数据源,JasperReports 非常灵活,允许您编写自己的自定义数据源。

JasperFillManager.fillReportToFile( "MasterReport.jasper" , parameters, getDataSource());

JasperFillManager.fillReportToFile( "MasterReport.jasper" , parameters, getDataSource());

This operation creates a Jasper print file (*.jrprint), which used to either print or export the report. - See more at: http://blog.manupk.com/2012/11/using-jasper-reports-to-create-reports.html#sthash.rFqV8K4i.dpuf

此操作会创建一个 Jasper 打印文件 (*.jrprint),用于打印或导出报告。- 查看更多信息:http: //blog.manupk.com/2012/11/using-jasper-reports-to-create-reports.html#sthash.rFqV8K4i.dpuf