您好,欢迎来到测品娱乐。
搜索
您的当前位置:首页JasperReport的使用过程

JasperReport的使用过程

来源:测品娱乐
Jasper Report (http://jasperforge.org/)

Minimum Requirements and required jar file to get started jasper report:              

Sun JDK 1.4 or later version

commons-beanutils-{version}.jar commons-collections-{version}.jar commons-digester-{version}.jar; commons-logging-{version}.jar; commons-logging-api-{version}.jar; itext-{version}.jar (pdf printing) jasperreports-{version}.jar jdt-compiler-{version}.jar

jxl-{version}.jar (excel printing) png-encoder-{version}.jar

poi-2.0-final-20040126.jar (excel printing) jfreechart-1.0.12.jar (chat printing) barbecue-1.1.jar (barcode printing)

iReport Getting Started

Step 1: Download, Install, and Run iReport Download in http://jasperforge.org/

To install iReport on a Windows platform: run iReport--windows-installer.exe. Start iReport using the menu item

Programs menu > Jaspersoft > iReport If you are using a Mac or a Linux box, consider to download iReport-.tar.gz, extract the archive in your favorite directory and run: iReport.sh. from a shell.

Step 2: Connect to a database

iReport can use several datasources to create reports, such as JDBC connection, XML file, CSV file, JavaBean result set, Hibernate connection, etc... This document will show how to create JDBC connection Data Source and XML file Data Source.

Add Oracle JDBC Driver to iReport iReport required to add the java jar file of the JDBC Driver. If you are connecting the Oracle database as the data source of the report, you have to add the jar file of oracle jdbc driver to iReport.

Adding Oracle class file for connection to Oracle database: Tools -> Options -> Classpath -> Add JAR

Add Data Source Click Report Datasource icon

-> New

Oracle JDBC connection 1. Click Database JDBC connection. 2. fill in the connection information XML file Data Source 1. Click XML file datasource 2. f ill in the connection information Step 3: Create your first report

Now you have setup a database connection, start the report wizard (File -> Report Wizard) to quickly create your first report. 1. Create an empty report “QuickQuote”

The layout of report can be split into : Title Band, Page Header Band, Column Header Band, Detail Band, Column Footer Band, Page Footer Band, Summary Band

In this report, we will use Title Band, Column Header Band and Detail Band only.

We can set the Band Height to 0 for unused band

Define the query for the data: Right click the mouse in blank area of iReport.

Type the sql statement for the data: e.g.

SELECT ID, QUICK_QUOTE_NO FROM mer_quick_quote where ID = '284e33e20a2bb9cb9ce510d0fe1007'

Add the following object, and preview the report.

Add SubReport:

Hide unused layout band:

Delete the $F{PICTURE}, and add an Image object into the layout. Set the value of the image as:

\"C:\\\\filesystem\\\dFiles\\\\QuickQuote\\\humbnail\\\\20090408\\\\\" + $F{PICTURE} + \".png\"

Preview the SubReport:

Preview the whole report:

Using Parameters in a Query and SubReport Query

Parameters may be used to filter a SQL query. Suppose you want to print information about a particular customer identified by customer ID (not known at design time). Your query will be as follows:

select * from customers

where CUSTOMERID = $P{MyCustomerId}

MyCustomerId is a parameter declared as an integer. JasperReports will transform this query to select * from customers where CUSTOMERID = ?

It will run this SQL using a prepared statement by passing the MyCustomerId value as a query parameter. If you would like to pass the parameter value directly, you can use this special syntax:

$P!{parameter_name}

This allows you to replace the parameter name in the query with its value. For example, if you have a parameter named MyWhere with the value of where CUSTOMERID = 5, the query select * from customers $P!{MyWhere} will be transformed into

select * from customers where CUSTOMERID = 5 by using this syntax.

Example:

SELECT ID, QUICK_QUOTE_NO FROM mer_quick_quote where ID = $P{docId}

Printing barcode in iReport

1. Add an image to the report

2. Set the Image Expression as: e.g.

com.core.merchant.common.image.BarcodeImage.getBarcodeImage(13,\"0815\l,0,0)

3. Set the Image Expression Class : java.awt.Image

SubReport with XML data source: Connection Type Data Source Expression Use a datasource expression ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource(\"/DOC/LIN\")

Jasper Printing in Merchant

Configured in struts-printing.xml

XML source to PDF -> xml_print_pdf.action XML source to Excel -> xml_print_excel.action XML source to HTML -> xml_print_html.action

Example to run the print feature in our system:

http://localhost:8083/merchantWeb/xml_print_pdf.action?reportName=PacSunPO&docId=0000201569.xml : Parameter Value Parameter Value reportName Jasper class file Name docId Xml file name DB to PDF -> jasper_print_pdf.action DB to Excel -> jasper_print_excel.action DB to HTML -> jasper_print_html.action

Example to run the print feature in our system:

http://localhost:8083/merchantWeb/jasper_print_pdf.action?reportName=QuickQuote&docId=284e33e20a2bb9cb9ce510d0fe1007

http://localhost:8083/merchantWeb/jasper_print_html.action?reportName=CHART

Useful link for jasper report and iReport.

iReport Tutorials

http://ireport-tutorial.blogspot.com/2008/11/what-is-ireport.html

Creating and Designing Report Using iReport (using old version as example)

http://aspalliance.com/1229_Creating_and_Designing_Report_Using_iReport__Part_1.all

JasperReport报表设计总结

http://www.javaeye.com/topic/78678

JasperReport经验谈

http://blog.csdn.net/zephyr_zhao/archive/2004/11/08/173003.aspx

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- cepb.cn 版权所有 湘ICP备2022005869号-7

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务