Summary of the use of Ireport&jasperrepor

Source: Internet
Author: User
Tags documentation

Written on: September 14, 2006
NOTE: You can reprint, reprint, please be sure to indicate the original source of the article and author information and this statement.

ireport is a report editing tool that outputs jrxml files (XML format) when the edits are complete. Jasperreport is an open source toolkit, the Jasperreport package can be added to the classpath can start to use the Jasperreport package, from the Java program through the call in the package of classes to Jrxml file operation, to complete the report compiled, Display, output and other work;

ireport Official website: http://jasperforge.org/sf/projects/ireport

Jasperreport Official website: http://jasperforge.org/sf/projects/jasperreports

Related forum:

matrix:http://www.matrix.org.cn/topic.shtml?forumid=48

IReport User Manual Download: http://www.matrix.org.cn/thread.shtml?topicId=38917&forumId=48 (author's fee document, English version)

ireport has provided some information about ireport video: http://ireport.sourceforge.net/docs.html

Jasperreport official guidelines for use: http://jasperreports.sourceforge.net/tutorial/index.html

Some examples provided by Jasperreport: http://jasperreports.sourceforge.net/samples/index.html

about the Chinese display should pay attention to the problem:

1, do the Chinese PDF report also need to Itextasian.jar to Lib.

Download Address: Http://itext.sourceforge.net/downloads/iTextAsian.jar

2. Right-click on the text field that needs to be displayed in Chinese-"Properties"-"Font" tab-fone Name Select "Sansserif", pdf Font Name Select "Stsong-light", and "PDF Embedded" on the hook, PDF Encoding Select Unigb-ucs2-h (Chinese Simplified) to correctly display the Chinese pull when compiling.

about the passing of parameters:

You can use parameters to populate a report if the data that you use to develop the report cannot be all introduced from one SQL statement. The parameters are introduced by the map object, first generating a Map object, and then adding the parameters to be used in the Map object.

HashMap Reportmap = new HashMap ();

The format for adding parameters to the Reportmap is as follows:

Reportmap.put ("parameter name defined in the report", string, or other type of argument);

Call Fillreporttofile or Fillreport format as follows (see Jasperreport API documentation): Jasperfillmanager.fillreporttofile ("Report.jasper", Reportmap, New Jremptydatasource (50));

Parameters can also be used in ireport SQL statements at design time. For example, query results required to display the value of x/y, and the value of Y is not directly from the SQL statement, you can introduce parameters, the value of y in the Java program, and then in the SQL statement "x/$P {y}" the way to use;

Note: When filling in the parameters, be aware that you want to keep the type in view-Parameters and the text field that uses the argument right-the type in Properties must be consistent.

in ireport method for calculating "totals" in a report:

The data that needs to be computed in the Java program is calculated by the way the parameter is displayed in the "LastPage Footer" method, which seems to be stupid, but it is still applicable.

IReport problem where the last page in the report cannot display page numbers:

Add the new Date (), "page" + $V {Page_number} + "of" and "+ $V {page_number}" text fields in LastPage footer, so that the page numbers appear correctly on the last page. Note that two rows of text fields that contain page numbers are seen in the report at this point, but it doesn't matter if the result is only one page and no two page number rows are displayed.

Jasperreport Middle JavaBean Use of:

In general, the report can be made by using SQL statements with parameters, and more complex reports may be produced using JavaBean as a data source.

1, first in "Data"-"Connection/datasource" set up a good JavaBean path.

2, in "Edit"-"Query"-"JavaBean DataSource" fill in the class name.

When the last tune is used, the data is introduced into the report through the collection object, as provided in the User manual:

public class Person

{

Private String name = "";

private int age = 0;

Public person (String name, int age)

{

THIS.name = name;

This.age = age;

}

public int Getage ()

{

return age;

}

Public String GetName () {

return name;

}

}

public class Testfactory

{

public static java.util.Collection Generatecollection ()

{

Java.util.Vector collection = new Java.util.Vector ();

Collection.add (New person ("Ted", 20);

Collection.add (New person ("Jack", 34));

Collection.add (New person ("Bob", 56));

Collection.add (New person ("Alice", 12));

Collection.add (New person ("Robin", 22);

Collection.add (New person ("Peter", 28));

return collection;

}

}

JasperReports Use 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.

More detailed information can refer to the API documentation in the Docs directory after the JasperReports engineering package is uncompressed.

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).

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.