IReport + jasperreport: how to create a sub-table (1), ireportjasper

Source: Internet
Author: User

IReport + jasperreport: how to create a sub-table (1), ireportjasper
Subtables are essential in the process of creating reports. Today I have studied several ways to create subtables.

1. Create a sub-table by connecting to the database

Take MySQL as an example:

Tables in my data source database


1) create a parent table in iReport

This is to create a new table, but remember to select mySQL as the data source. The same applies to other database data sources.

2) After the sub-table is created, we will create a sub-table and drag it to any place in the parent table on the component panel. I put it in detail.

It will generate a wizard

Next, just select use empty datasource In the last item, but select another one. We will modify it later.

3) Let's talk about the principle: This method uses the Parameters attribute that each report has. In iReport4.6, clicking a subreport has two attributes at the bottom of the attribute column on the right.


One is the Parameters attribute, which can be used to pass data to the sub-Table. Next I will talk about it. The second is the Return Values, which obviously can be used to Return the data of the sub-table. This will take some time.

Set the following table attributes:

Note that Subreport Expression is used to specify the path of the sub-Table. After the sub-table is created, it does not need to be modified.


The other is connect type, which should be set to Use a connectionexpress to select the default value when creating a sub-table, that is, the parent connection. This is not the focus now, but it is useful in subsequent methods.

The following are the key points:

Set and click Parameters to open such a window. Click add.

This is where your custom Parameters is located. The name can be obtained at will. My settings are as follows: the name is the id field of the database that I want to pass to the sub-Table. At this point, the settings for the master table end.

4) in the following settings, a key point is to create a Parameters in the left-side column of the sub-table, the new name in "right-click" should be the same as the one we created above, and the field type should be the same as the Field passed from the master table: I define the id and the ID field defined in my database is of the String type. Therefore, note that the Default Value Expection must be set to the "" character, otherwise, an error will be reported. It took me several hours.


After setting this, open the small button on the leftmost side of the Data Connection window. After opening it, use the select statement, but use our custom fields, such,

You will find that some attribute fields have been added.


My field and sub-table settings


The following is the preview result.


OK. This is the first way to create a sub-table. If you need to leave a mailbox, I will send the source code and hope to learn it together.

Go home, continue writing tomorrow



Report Generation Using ireport and Jasperreport

This process is generally used. However, you can use Java code to directly create a template, or use the relevant jar package of Jasperreport to compile the xml file. You do not have to use ireport as a template. In addition, this is only a solution to the report problem. I have other better solutions and tutorials. There are also several simple instances. I sent an offline message to the instance URL and an email to you. If you want a tutorial or other solutions, send your email to me. Or send me an Email.

Format setting when using iReport + JasperReport to create a report

② There are two methods. The first method is to combine the two values in a program or SQL statement before passing in the cell, the second is to splice the field or paramter to be set in the template, for example, $ V {PAGE_NUMBER }. toString () + "/" + $ V {PAGE_COUNT }. the result of toString () is to display "Current page/total page number"
③ Right-click the filed or parameter you want to display and select Field pattern in the displayed list. In the displayed dialog box, select Custom Format and enter yyyy-MM-dd HH: mm in the input box on the right: ss then select Date from the left, select the input yyyy-MM-dd HH: mm: ss in the right list, and click apply
④ In the left-side Navigation Pane, select Styles and click Parameters. You can create your own Styles, but you have provided many styles. If you want to apply a Style to select the parameter or filed you want to set, find the Style attribute in the attribute panel on the right, you can select the newly created Style or the Style provided by yourself.

Related Article

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.