Vous êtes sur la page 1sur 8

4/26/2011

Contents 1. 2. 3. 4. 5. 6. 7. 8. 9. Introduction iReport features Basic notions of JasperReport Building your first report Report structure Report elements Subreports Installation Refrences
2011 2

iReport & JasperReport


Course: Cng ngh java cho h thng phn tn Software Engineering Department Faculty of Information Technology University of Science, VNU HCMC. Presentation: Trng Phc Lc

Software Engineering Department

2011

Software Engineering Department

1. Introduction What is iReport?


A reporting tool. Developed in Java that helps users design reports visually. Using the JasperReports library to create reports.

1. Introduction (cont.) A report produced in iReport can be integrated in your open source or commercial application to Generate reports Display them on screen Export them in several formats including PDF, OpenOffce, DOCX, and many others. Send the final document directly to a printer.

What is JasperReports?
The open source reporting engine available for java community.

Software Engineering Department

2011

Software Engineering Department

2011

4/26/2011

1. Introduction (cont.)

2. iReport features Simple to use GUI Report designer and tools Data sources Report templates Export and review

Software Engineering Department

2011

Software Engineering Department

2011

3. Basic notions of JasperReport The report life cycle Jrxml sources and jasper files Data sources and print formats Expressions A simple program

3.1 The report life cycle


Java program Report src

Program java

*.jrxml *.dtd

Program class

Complier

*.jasper

Complier

1011

Interpreter

00111

Interpreter

Computer

Software Engineering Department

2011

Software Engineering Department

2011

4/26/2011

3.2 Jrxml source and Jasper file Jrxml file


report1.jrxml

3.2 Jrxml source and Jasper file (cont.) Jasper file


*.jrxml *.dtd

Report src

*.jasper

Complier

00111

Interpreter

Software Engineering Department

2011

Software Engineering Department

2011

10

3.3 Data sources and print formats

3.4 Expressions All of the formulas in JasperReports are defined through expressions

Software Engineering Department

2011

11

Software Engineering Department

2011

12

4/26/2011

3.4 Expressions (cont.) An expression is a java instruction which has an object as a result Expression examples are the following:
This is an expression new Boolean(true) new Integer(3) (($P{MyParam}.equals(S)) ? Yes : No)

3.5 A simple program


aa.java

Non valid expression examples are the following:


3+2*5 False (($P{MyParam} == 1) ? Yes : No) Software Engineering Department 2011

13

Software Engineering Department

2011

14

4. Building your first report Creating a new data source or database JDBC connection Creating a report using the wizard Using the design query feature to produce the SQL query for the report Viewing and exporting the report using the builtin viewer

5. Report structure Title Page header Column header Group header Detail Group footer Column footer Page footer Last page footer Summary Background
2011 16

Software Engineering Department

2011

15

Software Engineering Department

4/26/2011

5. Report structure (cont.) Report properties

5. Report structure (cont.) Columns

Software Engineering Department

2011

17

Software Engineering Department

2011

18

6. Report elements The basic elements offered by the JasperReports library: Line Rectangle Ellipse Static text Text field (or simply Field) Image Subreport
Software Engineering Department 2011 19

6. Report elements (cont.) Fields


The data sources in JasperReports are always organized in a set of records which are composed by a series of fields exactly like the results of an SQL query.

Variables
To calculate something during the runtime of the report.

Parameters
To pass data to the report engine. The data may be passed from another report, from any program, or directly from the user.

Groups

Software Engineering Department

2011

20

4/26/2011

6.1 Fields

6.2 Variables The properties of a variable: Name Variable class Calculation Reset type Reset group Variable Expression

Software Engineering Department

2011

21

Software Engineering Department

2011

22

6.3 Parameters The properties of a parameter Name Parameter Class Use as a prompt Default Value Expression

6.3 Parameters (cont.) HashMap hm = new HashMap(); hm.put(Parameter_Name, 2); ... JasperPrint print = JasperFillManager.fillReport( fileName, hm, new JREmptyDataSource());

Software Engineering Department

2011

23

Software Engineering Department

2011

24

4/26/2011

6.4 Groups Add group Delete group Variables for the group

7. Subreports A subreport is a complete report that is placed in another report. If you've got one item that is linked to several items in another table, such as a department and its employees, then a subreport is what you need. In such cases, generally, the main report (where the subreport is placed) contains the data of the master/parent table, and the subreport contains the data of the detail/child table.
25 Software Engineering Department 2011 26

Software Engineering Department

2011

7. Subreports (cont.) Creating the master report Creating the subreport Returning values from the subreport

8. Installation JDK 6 (link). MySQL 5.x (link). MySQL GUI tools (link). iReport (link).

Must add the files to library of the project commons-collections-xxx.jar commons-digester-xxx.jar, commons-logging-xxx.jar, jasperreports-xxx.jar.
(C:\Program Files\Jaspersoft\iReport-nb-3.7.0\ireport\modules\ext)
Software Engineering Department 2011 27 Software Engineering Department 2011 28

4/26/2011

9. References http://jasperforge.org/projects/ireport http://ireport-tutorial.blogspot.com iReport 3.7 Learn how to use iReport to create, design, format, and export reports

Q&A

Software Engineering Department

2011

29

Software Engineering Department

2011

30

Vous aimerez peut-être aussi