Using Jasperreport and ireport to make Java reports--(RPM)
Source: Internet
Author: User
Recently used jasperreports and ireport made a few reports, this piece is my summary.
JasperReports is an open source Java report making engine
Http://jasperreports.sourceforge.net
ireport is a GUI tool for JasperReports to generate JasperReports jrxml files.
Http://ireport.sourceforge.net
First use ireport to make a report template (my own noun):
Run ireport and create a new one.
Enter the name of the report in title band, as if using PageHeader band, and I haven't figured out 2 specific differences.
Place a few static text in the column header band as the columns heading for the report.
Put some TextField in the Detal band to display detailed data for the report.
In the summary band, put a textfield similar to "Total", which is shown in the last line of data decentralization.
In Lastpagefooter band, put the information you want to display on the last page, such as "Reviewer's signature."
This is basically the framework of the report, and then compile check for errors, and if there are no errors, you can use the report template in your program.
JasperReports Introduction:
Using JasperReports to generate reports is very simple, using only a few classes in the Net.sf.jasperreports.engine package to complete the report generation, preview, print, export and other functions.
1. Net.sf.jasperreports.engine.JasperCompileManager class.
Use several static methods of this class to complete the compilation of the report (see API documentation specifically)
There are two ways to Jaspercompilemanager when the compilation is complete:
1> returns a Jasperreport object
2> generates a. jasper file in the directory where the. jrxml file resides
Both of these methods are chosen by the programmer. However, I prefer to use the. jasper file, after all, the structure of the report is not changed every day, so it's not a good deal to recompile the report every time.
2. Net.sf.jasperreports.engine.JasperFillManager class
The function of this class is to populate the report with data. It can also be used with Jasperreport objects. Jasper file as a report template.
It also has 2 processing methods:
1> returns a Jsaperprint object.
2> generates a. jrprint file in the directory where the. jasper file resides
This class uses the implementation of the Net.sf.jasperreports.engine.JRDataSource interface as the data source. Any class that implements Jrdatasource can be used as a data source
Some data sources are defined in the Net.sf.jasperreports.engine.data package and can be selected according to your own needs. Here I'm using Jrtablemodeldatasource as
The data source (because my report is also displayed in the table).
3. Net.sf.jasperreports.engine.JasperPrintManager and Net.sf.jasperreports.engine.JasperExportManager
The role of the two classes is to print, export reports
They use Jasperprint and. jrprint files as input.
You can use the inside method according to your own needs.
Cases:
Import net.sf.jasperreports.engine.*;
Import net.sf.jasperreports.view.*;
public class Compilereport {
public static void Main (String args[]) {
try {
Compiling report.jrxml and generating report.jasper files in the directory where report.jrxml resides
Jaspercompilemanager.compilereporttofile ("Report.jrxml");
Fill in the data, here is the Jremptydatasource
Jasperfillmanager.fillreporttofile ("Report.jasper", NULL, New Jremptydatasource (50));
Preview the report, false to represent not using an XML file.
Jasperviewer view = new Jasperviewer ("Reports.jrprint", false);
View.pack ();
View.setvisible (TRUE);
}
catch (Exception e) {
E.printstacktrace ()
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service