The reports can be transformed or exported into other formats like PDF, HTML, and XLS using Facade class net.sf.jasperreports.engine.JasperExportManager. The transformation of the JasperPrint object (.jrprint file) into different format is known as exporting.
The following code (JasperReportExport.java) demonstrates the exporting process of the JasperReport document. The JasperExportManager provides methods to export a report into PDF, HTML, and XML only. To export to the XLS format, the class net.sf.jasperreports.engine.export.JRXlsExporter is used. This code generates following three files −
A report template is written. The contents of the JRXML file (C:\tools\jasperreports-5.0.1\test\jasper_report_template.jrxml) are as below −
Next, contents of the POJO file C:\tools\jasperreports-5.0.1\test\src\com\wisdomjobs\DataBean.java are as given below −
The contents of the file C:\tools\jasperreports-5.0.1\test\src\com\wisdomjobs\DataBeanList.java are as given below −
A main class file JasperReportFill.java, is written which gets the java bean collection from the class (DataBeanList) and passes it to the JasperReports engine, to fill the report template. Save it to the directory C:\tools\jasperreports-5.0.1\test\src\com\wisdomjobs.
The logic for exporting the jasper print file to pdf, html, xls format is included.
The above files are compiled and executed using regular ANT build process. The build.xml file is as given below −
Go to the command prompt and then go to the directory C:\tools\jasperreports-5.0.1\test, where build.xml is placed. Finally, execute the command ant -Dmain-class=com.wisdomjobs.JasperReportFill. The output is as follows −
It is observed that three files - sample_report.pdf, sample_report.html, sample_report.xls are being generated in the C:\ directory.
JasperReports Related Interview Questions
|Java Script Interview Questions||Adv Java Interview Questions|
|Qlik View Interview Questions||Hibernate Interview Questions|
|Finacle Interview Questions||SSRS(SQL Server Reporting Services) Interview Questions|
|Business Objects-Crystal Reports Interview Questions||Framework7 Interview Questions|
|Java collections framework Interview Questions||Java 8 Interview Questions|
|iReport Interview Questions||Structured Query Report (SQR) Interview Questions|
|Qlik Sense Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.