Académique Documents
Professionnel Documents
Culture Documents
JasperReports is an open-source Java class library designed to aid developers with the task of adding reporting capabilities to Java applications. It can be used to deliver dynamic content to the screen or printer. It can create reports in multiple formats, such as HTML file, PDF file, Excel file, CSV file , XML file, etc. It is capable of producing a report using data from a database, parameters, variables expressions and groups, etc. It also includes features, such as chart, crosstab, custom data sources, scriptlet, and subreport.
6-2
JasperReports
JasperReport is a framework or class library where developers have to create report template by writing all the XML codes (or more accurately jrxml) from scratch.
6-3
JasperReports
JasperReport uses XML file to define the report template. It is a bit difficult to define the report template by using purely XML code. Luckily we have iReport report designer, which provides us the ability to drag and drop to create report, no XML code writing needed. Note that iReport does not replace JasperReport, it is merely enhance the developer productivity in creating report template. We still require JasperReport framework or class library to provide us those API in order to compile and execute report.
6-4
iReport
6-5
Pre-requisite
To use Jasper reporting, you need 1. Netbeans IDE 6.0 or newer
2.
3.
Note: Newer versions (3.5.3, 3.6.0, 3.6.1, 3.6.2) can be found at the Website but may not work. You may use them if they work on your system.
Note: It is better to use the same version for both JasperReports and iReport. E.g., use JasperReport-3.6.1 with iReport 3.6.1.
6-6
Download JasperReport
You may browse the Web site to download jasperreports-3.5.2-project.zip or follows the direct link: http://sourceforge.net/projects/jasperreports/files/1.jasperreports/
6-7
Download iReport
You may browse the Web site to download iReport-nb-3.5.2-windows-installer.exe or follows the direct link: http://sourceforge.net/projects/ireport/files/ Download the standalone version.
6-8
10
11
Click Next.
12
13
14
15
16
17
18
Report section
Brief descriptions of the most important sections for designing a report are given below. title queryString pageHeader columnHeader detail columnFooter pageFooter Summary
19
>> pageHeader
This section appears at the top of each page in the report and can be used to display information such as dates, page numbers, etc. >> columnHeader This section is used to display the information as heading for each column.
20
>> pageFooter
This section appears at the bottom of each page in the report. >> Summary
This section contains the information that will be displayed at the end of the report.
21
22
JasperReports
Since JasperReports is not part of the standard Java API, we have to integrate the source files, bits, and documentation into NetBeans so that Netbeans can compile JasperReport class library or API. First, unzip jasperreports-3.5.2-project.zip to anywhere you like. Start Netbeans. Click Tools, then click Libraries.
23
Jasper Report
Click New Library and enter JasperReports-3.5.2 here.
24
Jasper Report
Click New Library and enter JasperReports-3.5.2 here.
25
Jasper Report
In the Classpath tab, add the jasperreports-1.2.5.jar file from the JasperReports dist directory and add the following 5 files from the lib directory:
commons-beanutils-1.8.0.jar!/
commons-collections-2.1.jar!/ commons-digester-1.7.jar!/ commons-javaflow-20060411.jar!/ commons-logging-1.0.2.jar!/ In the Sources tab, add the JasperReports src directory. Click OK to close Library Manager. You have successfully integrated the JaspertReport Compilation into Netbeans.
26
Jasper Report
27
28
29
30
4 5
31
32
33
35
Explanation of JasperFramework
JasperCompileManager.compileReport The compileReport method takes the JasperReports XML template and compiles it into byte code format (a JasperReports instance), which you can serialize to disk as a .jasper file. You can reuse the compiled templates to generate reports without compiling them unless you've changed the template source. JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
36
Explanation of JasperFramework
JasperFillManager.fillReport The fillReport method takes the compiled report (the JasperReports instance), a few user-defined custom parameters, and a JDBC datasource (the DB connection), In this simple product listing report example, the method fills in jasperReport object and connection.
37
Explanation of JasperFramework
JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, params, conn);
JasperReport object Connection object Parameter to pass into the report, for SQL or dynamic text content
38
Explanation of JasperFramework
JasperExportManager.viewReport The viewReport method displays the generated report in the built-in JasperReport Viewer. This is useful feature that enables you to quickly see how a report looks and you may print report from it directly. The 2nd parameter is a boolean data type to indicate the isExitOnClose state. If set to true, the whole application is closed when the JasperViewer is closed. False then otherwise. ( we always set it to false) JasperViewer.viewReport(jasperPrint, false);
39