Java Reference
In-Depth Information
Adding Multiple Columns to a Report
JasperReports allows us to generate reports with multiple columns. Reports we have
seen so far look like they have multiple columns. For example, the report we created
in the previous chapter, has four separate columns for Model, Tail Number, Serial
Number, and Engine. However, all four of these fields are laid out in a single <band> .
When we add multiple columns to a report, we should think of the data inside a
<band> as being in a cell, regardless of how the data is laid out inside that band.
The FlightStats database that we used for the examples in Chapter 4 contains
the country, state, and city where an aircraft is registered. Let us create a report
displaying the tail number of all the aircraft registered in the state of New York, in
the United States. Our report will display the data in three columns. The following
JRXML template will generate a report with the desired layout:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="MultipleColumnDemo" columnCount="3"
columnWidth="180">
<queryString>
<![CDATA[select a.tail_num
from aircraft a
where a.country = 'US'
and a.state = 'NY'
order by a.tail_num]]>
</queryString>
<field name="tail_num" class="java.lang.String"/>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="0" y="0" height="20" width="84"/>
<text>Tail Number</text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement x="0" y="0" height="20" width="84"/>
<textFieldExpression>
<![CDATA[$F{tail_num}]]>
 
Search WWH ::




Custom Search