"Ireport+jasperreport" 1.iReport and Jasperreport Foundation

Source: Internet
Author: User

1. What is ireport and Jasperreport
When it comes to ireport, we have to talk about Jasperreport first. Jasperreport is a report making program that users write an XML file according to the rules they make, and then get the file in the format that the user needs to output. It supports the output of file formats including PDF, HTML, XML, CSV, and so on.

When we use Jasperreport to make reports, we can be divided into the following two ways:
(1) Define a report directly with the program
(2) write an XML file to describe the report, usually with the help of ireport

Jasperreport do the report with all the underlying things, such as lines, static text, and so on, the bottom line is powerful, easy to control the report, but the disadvantage is that the writing is very troublesome. This time our ireport will come in handy, ireport is a support to complete the report interface design software, the software is completely to make up for the shortcomings of Jasperreport, the bottom of the writing to the visualization, greatly facilitate our.

The Jasperreport workflow is to first obtain the user-assembled XML file containing the information that needs to be output, and then compile the. Jasper type file from the XML file, and then this Jasper file can be loaded in our application to generate the final report. This is very similar to Java, in Java, There is a. java extension of the source file, the content in accordance with the rules of the Java language to write, the source file is compiled by the compiler to generate a. class file, when the class is used, it is in the form of an instance of the Java interpreter loaded into memory.

2. Software Installation
We need to install JDK, ireport and jasperreport.
Here my JDK version is 1.7 (actually requires more than 1.5 of the version is possible)
The version of my ireport is iReport4.1.3
My Jasperreport version is JasperReport4.1.3 (the jar package with Jasperreport already in the currently downloaded ireport)

As for how to download, everyone according to their own situation to major major web site can be downloaded to the above resources, here I will not be too much to repeat.

3. Use ireport to print the first report
Before we print the report, we first analyze the report format for the next jasperreport. The Jasperreport is divided vertically into several parts, each of which we call "band". Each band has its own characteristics, some will print once when the report is generated, and some will print multiple times.

Next we introduce each type of band separately.
(1) Title Band: The title field is displayed only on the top part of the first page of the entire report, except for the first page, no matter how many pages in the report will not appear in title band.

(2) PageHeader Band: As the name implies, the contents of the PageHeader segment will be in each page of the entire report
Appears in the upper part of the page, and if it is the first page of the report, the contents of the PageHeader are displayed in the
Under Title Band, the contents of PageHeader in all pages except the first page will be displayed at the top of the page.

(3) PageFooter Band: Appears at the bottom of the page.

(4) Lastpagefooter Band: Appears at the bottom of the last page.

(5) Detail Band: report content segment, in which you design reports that need to be repeated in the band, Detail segment
will appear on every page of the content.

(6) ColumnHeader Band: For detail band, the table of the report is normally drawn in this paragraph
Head.

(7) Columnfooter Band: The footer segment for detail band.

(8) Summary Band: The total segment of the table, which appears after detail band on the last page of the entire report,
Generally used to count the totals of one or several fields in a report.

Next, let's use the ireport for a bit.
First we open the ireport:



We choose to create a new report


Choose to create a A4 blank report, and then you'll see the Jasperreport report format that we talked about above:



We want to print the data, we need to get the data, so we want to get the data from the database. So we're going to use ireport to build DataSource with database links.

First we click on report Datasource


Click New to create a new connection, select a connection, here is the database JBDC connection


Fill in the correct driver and URL for the connection name, and click Test. Save after success (note that the database and tables here are prepared in advance).

Tip: If the driver is red, it means that there is no driver and the appropriate jar package needs to be added.
To add a jar package step:
Add the corresponding database driver jar in the ireport menu bar, "Tools"-"Options"-"classpath"-"Addjar".

Next, to demonstrate the effects of each band, we can add different objects to each band of the report to test the role of each band.
Right click on the name of the report, select Editorquery to open the reports query interface, enter your own SQL statement, the following interface appears:


After clicking OK, you'll see all the fields in the SQL query in the Fileds box in the main interface:


Next, we'll start designing our reports.
According to the requirements of the design of the report, the palette of different controls, you can choose according to their own needs. Drag the fields in the left field to place the data you want to print to where you want it,


To add a function to the report, in the toolbar on the left, you can choose variables to add the appropriate function. We have added the Page_number function here to count the pages.


Then we click on "Preview" to see the effect.

Last page:


The preview works fine.

At this point, our first report was printed successfully. We go to work space to see, will find a symbiotic into three files, respectively, the format is "Jrpxml", "Jrxml" and "Jasper" file. This later we use the Java API provided by Jasperreport, in the actual Java project to print the report of the time has an important role, we continue to explore next time.
Reprint Please specify Source: http://blog.csdn.net/acmman/article/details/51814181

"Ireport+jasperreport" 1.iReport and Jasperreport Foundation

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.