I have a Jasper Report that has a single detail section, and inside the detail section is a single field from the database that gets printed. So if my query returns 100 rows, I get 100 lines, which produces a report about 10 pages long, since 10 records fit on a page.
Is there a way I can print that field in columns, so that I can fit, say, 40 records on the page, instead of just 10? (By having 4 columns of 10)
You can configure a multi-column report. If you are using iReport, right click in the Report Inspector on the report name and select Page Format. In the Columns Section increase Columns from 1
to 4
, if desired configure Space to define a distance between the columns. If you click on the report you can also choose the Print order in the Properties panel.
In the report designer you drag the field in the first column in the detail band.
the added properties in the JRXML are in the <jasperreports ...
tag:
columnCount="4"
: 4 columnsprintOrder="Horizontal"
: fill order is horizontal.Attached the JRXML for further reference:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report8" language="groovy" columnCount="4" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="138" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5e2835cc-bc36-4f77-8631-08a8deaa28d7">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select 'A' as field]]>
</queryString>
<field name="field" class="java.lang.String"/>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="76707cdd-7dbe-477e-b3a4-38f9ba3bd003" x="0" y="0" width="136" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>