英文版:JasperReports报表工具[Reports made easy with JasperReports]

http://www.javaworld.com/javaworld/jw-09-2002/jw-0920-opensourceprofile.html

Generating reports is a common, if not always glamorous, task for programmers. In the past, report generation has largely been the domain of large commercial products such as Crystal Reports. Today, the open source JasperReports report generating library gives Java developers a viable alternative to commercial software.

JasperReports provides the necessary features to generate dynamic reports, including data retrieval using JDBC (Java Database Connectivity), as well as support for parameters, expressions, variables, and groups. JasperReports also includes advanced features, such as custom data sources, scriptlets, and subreports. All in all, JasperReports combines good features, maturity, community participation, and, best of all, it's free.

This article kicks off JavaWorld's new Open Source Profile column dedicated to Java-based open source tools and components. Look for upcoming articles spotlighting the Echo Web application framework and ObJectRelationalBridge, an object/relational mapping tool. Feel free to send me your suggestions for future articles.

Note: The documentation and code featured in this article are based on JasperReports version 0.3.3.

Report design
In JasperReports, you design reports using XML report templates. For example, the following XML file is a template for a report with a title, two columns of data, and page numbers:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="BasicReport" >
<parameter name="Title" class="java.lang.String"/>
<queryString><![CDATA[select name, cost from product]]></queryString>
<field name="NAME" class="java.lang.String"/>
<field name="COST" class="java.lang.Double"/>
<title>
<band height="50">
<textField>
<reportElement x="0" y="0" width="200" height="50" />
<textFieldExpression class="java.lang.String">$P{Title}</textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band>
</band>
</pageHeader>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="180" height="20"/>
<textElement>
<font isUnderline="true"/>
</textElement>
<text><![CDATA[NAME]]></text>
</staticText>
<staticText>
<reportElement x="360" y="0" width="180" height="20"/>
<textElement>
<font isUnderline="true"/>
</textElement>
<text><![CDATA[COST]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement x="180" y="0" width="180" height="20"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
<textField pattern="0.00">
<reportElement x="360" y="0" width="180" height="20"/>
<textFieldExpression class="java.lang.Double"><![CDATA[$F{COST}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band>
</band>
</columnFooter>
<pageFooter>
<band height="15">
<staticText>
<reportElement x="0" y="0" width="40" height="15"/>
<textElement/>
<text><![CDATA[Page:]]></text>
</staticText>
<textField>
<reportElement x="40" y="0" width="100" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band>
</band>
</summary>
</jasperReport>



The template's beginning includes any parameters passed into the report, the query that retrieves the data for the report, and the fields displayed in the report. The template's remainder divides into six report sections:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值