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"
<jasperReport name="MultipleColumnDemo" columnCount="3"
<![CDATA[select a.tail_num
from aircraft a
where = 'US'
and a.state = 'NY'
order by a.tail_num]]>
<field name="tail_num" class="java.lang.String"/>
<band height="20">
<reportElement x="0" y="0" height="20" width="84"/>
<text>Tail Number</text>
<band height="20">
<reportElement x="0" y="0" height="20" width="84"/>
Search WWH ::

Custom Search