How to create a table with both static and dynamic values from parameters? - jasper-reports

I want to create a table with static and dynamic values like the following picture:
As you can see, the red values are dynamic (values in parameters) while the rest of the table is static.
The problem is that I cannot add more than one detail row to the table.
Even if I use normal Text Field and Static Text elements instead of a Table I wouldn't be able to stretch the values (in case a value needs more than a single line) without overlapping.
How can I achieve this?

To use the jr:table component you need to have a datasource, normally you should get the data from some backend code, passing it to the report for example as a List in a parameter. Hence instead of passing the single parameters, you pass a datasource with both name and values.
However, for fun? we can create a datasource also within the jrxml code for example in your case I would use a ListOfArrayDataSource(java.util.List<java.lang.Object[]> records, java.lang.String[] columnNames)
The code to create the first two entries would be something this.
new net.sf.jasperreports.engine.data.ListOfArrayDataSource(
Arrays.asList(
new String[]{"Name", $P{name}},
new String[]{"Date of Birth", $P{dateOfBirth}}
),
new String[]{"c1", "c2"}
)
Full jrxml
<?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="Blank_A4_15" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="342c93fd-9f0b-49db-a6e8-dbc252bbeca4">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Dataset" uuid="604ce812-0b69-47fa-862f-c6b4356c6b62">
<queryString>
<![CDATA[]]>
</queryString>
<field name="c1" class="java.lang.String"/>
<field name="c2" class="java.lang.String"/>
</subDataset>
<parameter name="name" class="java.lang.String">
<defaultValueExpression><![CDATA["Nasser Ali"]]></defaultValueExpression>
</parameter>
<parameter name="dateOfBirth" class="java.lang.String">
<defaultValueExpression><![CDATA["1985-10-07"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="61" splitType="Stretch">
<staticText>
<reportElement mode="Opaque" x="0" y="1" width="400" height="30" forecolor="#FFFFFF" backcolor="#000000" uuid="56949b5f-9b21-4f88-9660-ddccce0e7cad"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Personal information]]></text>
</staticText>
<componentElement>
<reportElement x="0" y="31" width="400" height="30" uuid="7a9309f0-4b5f-4c01-9b0a-611807b01f96">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset" uuid="f682c987-479a-40f9-8b97-bf07577e67fa">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.ListOfArrayDataSource(Arrays.asList(new String[]{"Name", $P{name}}, new String[]{"Date of Birth", $P{dateOfBirth}}),new String[]{"c1", "c2"})]]></dataSourceExpression>
</datasetRun>
<jr:column width="200" uuid="c087b83b-e6f9-4366-b655-eb7c14e35745">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="200" height="30" uuid="dce0c9d6-ec99-4cbb-b981-73d3dff1b67b"/>
<box leftPadding="5"/>
<textElement verticalAlignment="Middle">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{c1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="200" uuid="dad64648-00cb-46ff-9f74-216170605bf6">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:detailCell style="Table_TD" height="30">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<textField>
<reportElement x="0" y="0" width="200" height="30" forecolor="#FF0400" uuid="05d673a9-93d4-4b3e-a4eb-6fd5fd171b30"/>
<box leftPadding="5"/>
<textElement verticalAlignment="Middle">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{c2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</title>
</jasperReport>
Output:

Related

How do I prevent text overflowing into the next cell in a Jasper Report that exports to Excel?

I am creating a jrxml in Jaspersoft Studio that exports a table to Excel. When I view the Excel output, the data in the last column is overflowing into the next cell like so:
I am trying to prevent the data from overflowing into the next cell without wrapping the data in the cell.
I was able to find a reference for why Excel does overflow text: https://www.ablebits.com/office-addins-blog/stop-text-spilling-over-excel/
One of the solutions is to manually Format Cells and change horizontal text alignment to 'Fill'. This gives me the following table, which is exactly what I need:
However, I was not able to find a way to configure my jrxml to obtain this behavior. How may I create my jrxml such that it will export to Excel without overflowing text into adjacent columns (without wrapping the text)?
I don't think text alignment 'Fill' can be set when exporting to XLS.
One (kinda dirty) solution is having a 'blank' cell next to COL2 which will prevent the text in COL2 overflowing into the 'blank' cell.
Your example (modified):
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.0.final using JasperReports Library version 6.1.1 -->
<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="Blank_A4" pageWidth="240" pageHeight="400" columnWidth="200" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="af068097-e37b-4e41-9083-4c7b8e13c800">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="net.sf.jasperreports.export.xls.wrap.text" value="false"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<subDataset name="Dataset1" uuid="f12cc232-2035-43e1-b3e3-a446ee7318bf">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[select 'abcdefghijklmnopqrstuvwxyz' as data1,
'abcdefghijklmnopqrstuvwxyz' as data2]]>
</queryString>
<field name="data1" class="java.lang.String"/>
<field name="data2" class="java.lang.String"/>
</subDataset>
<queryString>
<![CDATA[select 1]]>
</queryString>
<detail>
<band height="359" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="220" height="60" uuid="6a7376a7-6ee6-4e94-8e7b-024170505320">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<c:table xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="0fee875c-6568-4a06-a8e4-f7fb34ebd4e5"/>
<c:column width="100" uuid="6517d845-8cbe-44b6-a644-cedfc40576c9">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<c:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement mode="Opaque" x="0" y="0" width="100" height="30" forecolor="#FFFFFF" backcolor="#7845D9" uuid="f222fdba-a6db-46dd-97a5-e8e0181aa7e4">
<propertyExpression name="net.sf.jasperreports.export.xls.wrap.text"><![CDATA["true"]]></propertyExpression>
</reportElement>
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="1.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[COL1]]></text>
</staticText>
</c:columnHeader>
<c:detailCell height="30">
<textField isBlankWhenNull="true">
<reportElement mode="Opaque" x="0" y="0" width="100" height="30" uuid="2a235121-a4f3-487b-8138-edc5b5340e50"/>
<box>
<pen lineWidth="0.5"/>
</box>
<textElement verticalAlignment="Middle">
<paragraph leftIndent="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{data1}]]></textFieldExpression>
</textField>
</c:detailCell>
</c:column>
<c:column width="100" uuid="23415ab5-ef42-4f13-9395-cc9bb019149a">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<c:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement mode="Opaque" x="0" y="0" width="100" height="30" forecolor="#FFFFFF" backcolor="#7845D9" uuid="8ecbe731-1442-40b4-94a6-f3c57337704c">
<propertyExpression name="net.sf.jasperreports.export.xls.wrap.text"><![CDATA["true"]]></propertyExpression>
</reportElement>
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="1.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[COL2]]></text>
</staticText>
</c:columnHeader>
<c:detailCell height="30">
<textField isBlankWhenNull="true">
<reportElement mode="Opaque" x="0" y="0" width="100" height="30" uuid="c8f16b37-4f63-4043-abc6-d321125c247e"/>
<box>
<pen lineWidth="0.5"/>
</box>
<textElement verticalAlignment="Middle">
<paragraph leftIndent="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{data2}]]></textFieldExpression>
</textField>
</c:detailCell>
</c:column>
<c:column width="20" uuid="4fff907e-9cb8-41d3-a264-b78ca5ed814a">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
<c:columnHeader height="30" rowSpan="1"/>
<c:detailCell height="30">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<textField>
<reportElement x="0" y="0" width="20" height="30" uuid="eb0dd902-0635-4a55-8f84-03834107f2bf"/>
<textFieldExpression><![CDATA[""]]></textFieldExpression>
</textField>
</c:detailCell>
</c:column>
</c:table>
</componentElement>
</band>
</detail>
</jasperReport>

How to create a table with repeating the parent element values in Jasper report

I have a requirement to create a table using JSON data using Jasperstudio 6.2.12 and export it to .xlsx format. I'm able to create the table as shown below:
The requirement I have is to iterate the values in A, B, C, and D columns based on the number of rows in the E and F columns. The expected output is:
The JSON data I've used to print the table is :
{
"root": [{
"firstName": "John",
"lastName": "Doe",
"accounts": [{
"bank": "LLOYDS",
"accountNumber": 123456,
"references": [{
"name": "Eva Doe",
"refAccountNumber": 6549873
},
{
"name": "Robin Doe",
"refAccountNumber": 3216545
},
{
"name": "Peter Doe",
"refAccountNumber": 9876549
}
]
}]
},
{
"firstName": "James",
"lastName": "Doe",
"accounts": [{
"bank": "HSBC",
"accountNumber": 654321,
"references": [{
"name": "Sam Doe",
"refAccountNumber": 6549873
},
{
"name": "Roger Doe",
"refAccountNumber": 3216545
},
{
"name": "Jason Doe",
"refAccountNumber": 9876549
}
]
}]
}
]}
JRXML:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.13.0.final using JasperReports Library version 6.13.0-46ada4d1be8f3c5985fd0b6146f3ed44caed6f05 -->
<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="accounts" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="066cfa9f-bcf0-4095-8d82-a5ef1cb8632d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Test"/>
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
<property name="net.sf.jasperreports.export.xls.white.page.background" value="false"/>
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
<property name="net.sf.jasperreports.export.xls.ignore.graphics" value="false"/>
<property name="net.sf.jasperreports.page.break.no.pagination" value="apply"/>
<property name="net.sf.jasperreports.export.xls.sheet.names.all" value="Accounts"/>
<property name="net.sf.jasperreports.export.xls.freeze.row" value="1"/>
<property name="net.sf.jasperreports.print.keep.full.text" value="true"/>
<property name="net.sf.jasperreports.exports.xls.font.size.fix.enabled" value="false"/>
<property name="maximumRowsPerSheet" value="0"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="AccountsDataset" uuid="73085770-27bc-42cb-b4db-edc97074de2c">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Test"/>
<queryString language="json">
<![CDATA[root.accounts]]>
</queryString>
<field name="bank" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="bank"/>
<fieldDescription><![CDATA[bank]]></fieldDescription>
</field>
<field name="accountNumber" class="java.lang.Integer">
<property name="net.sf.jasperreports.json.field.expression" value="accountNumber"/>
<fieldDescription><![CDATA[accountNumber]]></fieldDescription>
</field>
<field name="accoutType" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="accoutType"/>
<fieldDescription><![CDATA[accoutType]]></fieldDescription>
</field>
<field name="references" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="references"/>
<fieldDescription><![CDATA[references]]></fieldDescription>
</field>
</subDataset>
<subDataset name="ReferencesDataset" uuid="b23c5f84-b106-4d89-a5d4-6287aa8bbdf7">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Test"/>
<queryString language="json">
<![CDATA[root.accounts.references]]>
</queryString>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="name"/>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="refAccountNumber" class="java.lang.Integer">
<property name="net.sf.jasperreports.json.field.expression" value="refAccountNumber"/>
<fieldDescription><![CDATA[refAccountNumber]]></fieldDescription>
</field>
</subDataset>
<subDataset name="MainDataset" uuid="ab297ea1-81e6-4a6f-b90c-4ce1fb9521a2">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Test"/>
<queryString language="json">
<![CDATA[root]]>
</queryString>
<field name="firstName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="firstName"/>
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="lastName"/>
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<field name="email" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="email"/>
<fieldDescription><![CDATA[email]]></fieldDescription>
</field>
<field name="accounts" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="accounts"/>
<fieldDescription><![CDATA[accounts]]></fieldDescription>
</field>
</subDataset>
<queryString language="json">
<![CDATA[]]>
</queryString>
<field name="root" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="root"/>
<fieldDescription><![CDATA[root]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="254" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="480" height="60" uuid="268fe625-e43f-48d5-90c7-f396d09cd88d">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="MainDataset" uuid="67830a07-2594-4532-ae34-96829b8046da">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("root")]]></dataSourceExpression>
</datasetRun>
<jr:column width="80" uuid="a8cf3aa0-1633-4f19-a908-6efbf55d2f75">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="b89609d4-5cbb-4f5b-b470-c9f9f4ad9d26"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[First Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="ec954e2c-43e4-43ba-9005-03272b9daad5"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="e7f5cfca-a803-485d-be01-5d2f785fbf0b">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="0a2eb2ed-75b9-46c3-8751-871c5473c3e1"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Last Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="767b9d15-53e5-4a0b-be8c-ec94fc6398f8"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{lastName}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="c7103510-df1d-4c31-a30f-9b726540dd7a">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="11192151-2c03-4590-91f7-87021b022301"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Bank]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<componentElement>
<reportElement x="0" y="0" width="80" height="30" uuid="8b2678af-1b87-49e6-aca2-af0cec3d7a46"/>
<jr:list printOrder="Vertical">
<datasetRun subDataset="AccountsDataset" uuid="faa7fa1c-7169-48fb-aac2-7483a2477998">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("accounts")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="80">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="97ec29f7-36f2-4ecc-9f30-3049e0648e97"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{bank}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="5a4bb23a-7d61-486b-91f8-b5150cb85817">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column4"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="30680d44-df3b-484e-b059-399e0a21b304"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Account Number]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<componentElement>
<reportElement x="0" y="0" width="80" height="30" uuid="d7780443-ba11-4d20-944d-4f8210a74506"/>
<jr:list printOrder="Vertical">
<datasetRun subDataset="AccountsDataset" uuid="2c245f1d-7a8f-46dc-85c3-737b5b0bc5a1">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("accounts")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="80">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="ba6b13f3-770d-4a02-b3f0-5d4293393cd3"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{accountNumber}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="0720c554-a0af-4192-a669-38cea560a2e2">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column5"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="98adb234-9003-4704-85e4-295538f4273c"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Ref Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<componentElement>
<reportElement x="0" y="0" width="80" height="30" uuid="faf83492-91ac-4a39-9483-512d6555c3d3"/>
<jr:list printOrder="Vertical">
<datasetRun subDataset="ReferencesDataset" uuid="832a218b-199c-4055-9891-0afaf629bf50">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("accounts.references")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="80">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="955502f3-afec-40aa-a8f8-b5e83d43bcbc"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="2aed257e-00f2-4594-a9ac-9b504262ee3e">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column6"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="be058bb0-b9f3-4b41-b074-c1f44350eb09"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Ref Account Number]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<componentElement>
<reportElement x="0" y="0" width="80" height="30" uuid="ed5f0c5e-8f14-4565-8159-b7528e035f3c"/>
<jr:list printOrder="Vertical">
<datasetRun subDataset="ReferencesDataset" uuid="2c2d0c12-930c-45c5-a3a1-f8228fc78d7f">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("accounts.references")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="80">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="59563298-0f0f-4b62-b263-511abb945d1a"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{refAccountNumber}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
Please help me to iterate the values in A, B, C, and D columns based on the number of rows in the E and F columns and get the expected output. Thank you all so much!
The easiest way to do this is to use a single subdataset that has the fields from all levels of the JSON tree. To do that you'll have to switch to the JSONQL query executer, which allows you to map fields from the parent nodes of the ones selected by the data source.
Once you have all the fields in a single dataset, you can use a simple table to display them.
The report would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.13.0.final using JasperReports Library version 6.13.0-46ada4d1be8f3c5985fd0b6146f3ed44caed6f05 -->
<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="accounts" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="066cfa9f-bcf0-4095-8d82-a5ef1cb8632d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Test"/>
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
<property name="net.sf.jasperreports.export.xls.white.page.background" value="false"/>
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
<property name="net.sf.jasperreports.export.xls.ignore.graphics" value="false"/>
<property name="net.sf.jasperreports.page.break.no.pagination" value="apply"/>
<property name="net.sf.jasperreports.export.xls.sheet.names.all" value="Accounts"/>
<property name="net.sf.jasperreports.export.xls.freeze.row" value="1"/>
<property name="net.sf.jasperreports.print.keep.full.text" value="true"/>
<property name="net.sf.jasperreports.exports.xls.font.size.fix.enabled" value="false"/>
<property name="maximumRowsPerSheet" value="0"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="ReferencesDataset" uuid="b23c5f84-b106-4d89-a5d4-6287aa8bbdf7">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Test"/>
<queryString language="jsonql">
<![CDATA[root.accounts.references]]>
</queryString>
<field name="firstName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^^^^.firstName"/>
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^^^^.lastName"/>
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<field name="bank" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^^.bank"/>
<fieldDescription><![CDATA[bank]]></fieldDescription>
</field>
<field name="accountNumber" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^^.accountNumber"/>
<fieldDescription><![CDATA[accountNumber]]></fieldDescription>
</field>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="name"/>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="refAccountNumber" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="refAccountNumber"/>
<fieldDescription><![CDATA[refAccountNumber]]></fieldDescription>
</field>
</subDataset>
<queryString language="jsonql">
<![CDATA[]]>
</queryString>
<field name="root" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="root"/>
<fieldDescription><![CDATA[root]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="254" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="480" height="60" uuid="268fe625-e43f-48d5-90c7-f396d09cd88d">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="ReferencesDataset" uuid="67830a07-2594-4532-ae34-96829b8046da">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("root.accounts.references.*")]]></dataSourceExpression>
</datasetRun>
<jr:column width="80" uuid="a8cf3aa0-1633-4f19-a908-6efbf55d2f75">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="b89609d4-5cbb-4f5b-b470-c9f9f4ad9d26"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[First Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="ec954e2c-43e4-43ba-9005-03272b9daad5"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="e7f5cfca-a803-485d-be01-5d2f785fbf0b">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="0a2eb2ed-75b9-46c3-8751-871c5473c3e1"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Last Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="767b9d15-53e5-4a0b-be8c-ec94fc6398f8"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{lastName}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="c7103510-df1d-4c31-a30f-9b726540dd7a">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="11192151-2c03-4590-91f7-87021b022301"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Bank]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="97ec29f7-36f2-4ecc-9f30-3049e0648e97"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{bank}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="5a4bb23a-7d61-486b-91f8-b5150cb85817">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column4"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="30680d44-df3b-484e-b059-399e0a21b304"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Account Number]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="ba6b13f3-770d-4a02-b3f0-5d4293393cd3"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{accountNumber}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="0720c554-a0af-4192-a669-38cea560a2e2">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column5"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="98adb234-9003-4704-85e4-295538f4273c"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Ref Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="955502f3-afec-40aa-a8f8-b5e83d43bcbc"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="80" uuid="2aed257e-00f2-4594-a9ac-9b504262ee3e">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column6"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<staticText>
<reportElement x="0" y="0" width="80" height="30" uuid="be058bb0-b9f3-4b41-b074-c1f44350eb09"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Ref Account Number]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="80" height="30" uuid="59563298-0f0f-4b62-b263-511abb945d1a"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{refAccountNumber}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>

Jaspersoft page wrong orientation on print

I have a jasper report to print a little invoice in portrait orientation, but whem I send to print, it's in landscape and takes up a lot of space at the A4 page.
How can I do to fix the orientation to maintain as portrait?
I've tryed to put the code of my jrxml here, but i'ts big, so, on the link you can download the .jxrml or by pastebin.
invoice.jrxml
Invoice by pastebin
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1 -->
<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="recibo" pageWidth="538" pageHeight="842" columnWidth="518" leftMargin="10" rightMargin="10" topMargin="10" bottomMargin="10" isIgnorePagination="true" uuid="11534e1c-358a-479d-bf93-b6f8c442b8f6">
<property name="ireport.zoom" value="2.479338842975207"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="131"/>
<property name="com.jaspersoft.studio.unit." value="cm"/>
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="cm"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="cm"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="cm"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="cm"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="cm"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="cm"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="cm"/>
<parameter name="LOGO_EMITENTE" class="java.lang.Object" isForPrompting="false"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="tit.identificacao" class="java.lang.String"/>
<field name="tit.valor" class="java.lang.Double"/>
<field name="tit.valor_ext" class="java.lang.String"/>
<field name="pag.nome" class="java.lang.String"/>
<field name="tit.dtPag" class="java.lang.String"/>
<field name="emit.fant" class="java.lang.String"/>
<field name="emit.xNome" class="java.lang.String"/>
<field name="emit.xLgr" class="java.lang.String"/>
<field name="emit.nro" class="java.lang.String"/>
<field name="emit.xCpl" class="java.lang.String"/>
<field name="emit.xBairro" class="java.lang.String"/>
<field name="emit.cep" class="java.lang.String"/>
<field name="emit.xMun" class="java.lang.String"/>
<field name="emit.uf" class="java.lang.String"/>
<field name="emit.fone" class="java.lang.String"/>
<field name="emit.nrDocumento" class="java.lang.String"/>
<field name="emit.ie" class="java.lang.String"/>
<field name="emit.im" class="java.lang.String"/>
<field name="tit.dtPagExtenso" class="java.lang.String"/>
<field name="rec.nome" class="java.lang.String"/>
<detail>
<band height="180">
<property name="com.jaspersoft.studio.layout"/>
<frame>
<reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="518" height="180" uuid="c0e55f85-87e9-440d-ae9b-b3c4567027e5">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box leftPadding="0" bottomPadding="0" rightPadding="0">
<pen lineWidth="0.0"/>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="1.0"/>
</box>
<staticText>
<reportElement x="121" y="9" width="270" height="20" uuid="1e5ac468-8b43-444b-9b66-fb0e81427f12">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Monospaced" size="14" isBold="true"/>
</textElement>
<text><![CDATA[RECIBO]]></text>
</staticText>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" x="80" y="32" width="435" height="20" uuid="dc2e375a-32f1-4ca7-8094-abcd3198af0e"/>
<textElement textAlignment="Left" verticalAlignment="Top">
<font fontName="Monospaced" size="8" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{pag.nome}]]></textFieldExpression>
</textField>
<textField pattern="¤ #,##0.00;¤ -#,##0.00" isBlankWhenNull="true">
<reportElement positionType="Float" x="396" y="8" width="119" height="20" uuid="90210ce2-92ef-418d-bde0-8e9f5b675576"/>
<textElement textAlignment="Right" verticalAlignment="Top">
<font fontName="Monospaced" size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{tit.valor}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="¤#,##0.00;¤-#,##0.00" isBlankWhenNull="true">
<reportElement positionType="Float" x="60" y="83" width="454" height="20" uuid="35a3c249-1a76-43ce-a290-eb754bee83af">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Left" verticalAlignment="Top">
<font fontName="Monospaced" size="8" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{tit.identificacao}]]></textFieldExpression>
</textField>
<staticText>
<reportElement positionType="Float" x="459" y="172" width="52" height="8" uuid="7a716ed8-4f4e-44d4-a699-275510648c8a"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Monospaced" size="5" isItalic="true"/>
</textElement>
<text><![CDATA[www.sentus.com.br]]></text>
</staticText>
</frame>
<staticText>
<reportElement x="2" y="32" width="78" height="12" uuid="19cd0546-23ff-4e55-b549-822b7a737b09"/>
<textElement textAlignment="Left" verticalAlignment="Top">
<font fontName="Monospaced" size="8"/>
</textElement>
<text><![CDATA[Recebi(emos) de]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" x="2" y="52" width="58" height="12" uuid="88baf49a-023a-42ce-821e-7ef6bcd17b95"/>
<textElement textAlignment="Left" verticalAlignment="Top">
<font fontName="Monospaced" size="8"/>
</textElement>
<text><![CDATA[a quantia de]]></text>
</staticText>
<textField isStretchWithOverflow="true" pattern="¤#,##0.00;¤-#,##0.00" isBlankWhenNull="true">
<reportElement positionType="Float" x="60" y="52" width="455" height="24" uuid="ea680987-de0f-4766-89fc-f1fce0b2f47b">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Left" verticalAlignment="Top">
<font fontName="Monospaced" size="8" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{tit.valor_ext}]]></textFieldExpression>
</textField>
<staticText>
<reportElement positionType="Float" x="2" y="83" width="58" height="12" uuid="753a6211-5cf0-4bc8-a703-14a204e80e60">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<textElement textAlignment="Left" verticalAlignment="Top">
<font fontName="Monospaced" size="8"/>
</textElement>
<text><![CDATA[referente à]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="2" y="107" width="204" height="12" uuid="854cc28e-80fe-4fd2-9d55-0c5c9b850075"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Monospaced" size="8"/>
</textElement>
<text><![CDATA[e para clareza firmo(amos) o presente.]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement positionType="Float" x="153" y="130" width="220" height="12" uuid="c8231b66-f3f2-42b8-bcc0-7f6c29acfb58"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Monospaced" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{emit.xMun} + ", " + $F{tit.dtPagExtenso}]]></textFieldExpression>
<patternExpression><![CDATA[$F{emit.xMun}]]></patternExpression>
</textField>
<line>
<reportElement positionType="FixRelativeToBottom" x="193" y="158" width="149" height="1" uuid="4d95856f-f0ec-427d-bfc6-bc012da4f236"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<staticText>
<reportElement positionType="Float" x="163" y="170" width="204" height="10" uuid="a839d66e-220b-48e5-a15b-7021aac21b25"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Monospaced" size="7" isBold="false"/>
</textElement>
<text><![CDATA[Assinatura]]></text>
</staticText>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" x="163" y="160" width="204" height="10" uuid="3287959a-43aa-472d-8589-c1e777b8a146"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Monospaced" size="7" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{rec.nome}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Thank you
I solved the problem creating a new report with the correct A4 size, and inside of it, I put my old report invoice.jrxml that I mentioned in the question.
It worked perfectly.
invoice_A4.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1 -->
<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="recibo_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenResourceMissingType="Empty" uuid="97db2eb7-eacb-4a72-af21-544bfd5ffe59">
<property name="com.jaspersoft.studio.unit." value="cm"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="cm"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="cm"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="cm"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="cm"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="cm"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="cm"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="cm"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="cm"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="recibos" class="java.lang.Object"/>
<detail>
<band height="802" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<frame>
<reportElement key="" x="0" y="0" width="555" height="802" uuid="7896b407-46da-4b1a-a3c7-835e45d14bc5">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<subreport>
<reportElement x="0" y="0" width="555" height="802" uuid="ca317fd4-37db-4802-be56-943b67fd4189"/>
<dataSourceExpression><![CDATA[$F{recibos}]]></dataSourceExpression>
<subreportExpression><![CDATA["reports/recibo.jasper"]]></subreportExpression>
</subreport>
</frame>
</band>
</detail>
</jasperReport>

use Table dataset field value in main report

<?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="TestingImage" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="5470e3fc-1c9c-4841-8814-e3a935fa6684"> <property name="ireport.zoom" value="1.0"/><property name="ireport.x" value="0"/><property name="ireport.y" value="229"/><style name="table"><box><pen lineWidth="1.0" lineColor="#000000"/></box></style><style name="table_TH" mode="Opaque" backcolor="#F0F8FF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style><style name="table_CH" mode="Opaque" backcolor="#BFE1FF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style><style name="table_TD" mode="Opaque" backcolor="#FFFFFF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style><style name="Table_TH" mode="Opaque" backcolor="#F0F8FF"><box><pen lineWidth="0.5" lineColor="#000000"/><topPen lineWidth="0.5" lineColor="#000000"/><leftPen lineWidth="0.5" lineColor="#000000"/><bottomPen lineWidth="0.5" lineColor="#000000"/<rightPen lineWidth="0.5" lineColor="#000000"/></box></style><style name="Table_CH" mode="Opaque" backcolor="#BFE1FF"><box><pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="ImageDemoDataset" uuid="47414685-b792-4a30-9b14-fc32127ad3cc">
<parameter name="lastname" class="java.lang.String">
<defaultValueExpression><![CDATA[$F{picture}]]></defaultValueExpression>
</parameter>
<parameter name="firstname" class="java.lang.String">
<defaultValueExpression><![CDATA[$F{firstname}]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="firstname" class="java.lang.String"/>
<field name="lastname" class="java.lang.String"/>
<field name="email" class="java.lang.String"/>
<field name="phone_number" class="java.lang.String"/>
<field name="picture" class="java.lang.String"/>
<variable name="imagePath" class="java.lang.String" resetType="None">
<variableExpression><![CDATA[$F{picture}]]></variableExpression>
</variable>
</subDataset>
<parameter name="ImageDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<variable name="varImage" class="java.lang.String" resetType="None"/>
<detail>
<band height="364" splitType="Stretch">
<componentElement>
<reportElement x="18" y="0" width="474" height="216" uuid="771aa5d8-1470-4fd9-b062-a913b6014f19">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="ImageDemoDataset" uuid="c4a063af-d8d1-41c4-98bf-660a9eab651e">
<dataSourceExpression><![CDATA[$P{ImageDataSource}]]></dataSourceExpression>
<returnValue fromVariable="imagePath" toVariable="varImage"/>
</datasetRun>
<jr:column width="70" uuid="6aa96500-79ab-4b8b-aa5f-0c9dbc22638f">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="70" height="30" uuid="9528bbd1-627c-424c-a3f0-872f92799c94"/>
<textFieldExpression><![CDATA[$F{firstname}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="ba88fb55-d423-4d1e-99a1-b81c44f6e65a">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="5c85fd56-54ba-4d22-a3e4-adcdbbbc2b4f"/>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{lastname} ]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="29524685-b68a-4906-be22-50b0acacba7d">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="9dacce68-21ca-4bcc-b9cb-bad1b3661611"/>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="94" uuid="4bb9635f-4173-4c5b-95ce-5a12a2332ea1">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="94" height="30" uuid="8c6c58b1-d3fd-4fad-995a-caaaea6afe8e"/>
<textFieldExpression><![CDATA[$F{phone_number}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="b500de9f-6abf-41b8-9e5d-d408b94d32ce">
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="0e6a1e56-974f-41a3-af08-0cf5b832b573"/>
<textFieldExpression><![CDATA[$F{picture}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<image scaleImage="FillFrame" hAlign="Center" vAlign="Middle">
<reportElement x="48" y="266" width="100" height="98" uuid="290e1eb9-3a18-4a65-93d4-d155b98ce964">
<printWhenExpression><![CDATA[!$V{varImage}.equalsIgnoreCase("null")]]></printWhenExpression>
</reportElement>
<imageExpression><![CDATA["C:\\Users\\jigpra\\Pictures\\"+$V{varImage}]]></imageExpression>
</image>
<staticText>
<reportElement x="48" y="231" width="100" height="20" uuid="32fd136d-d7c4-4256-be6c-e9ad7d5f7592"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[$V{varImage}]]></text>
</staticText>
</band>
</detail>
I want to use Table dataset Field/parameter in Main report. I added data of collection in table to show upin this data I have one value is image for every column. I want to get that Image name (currently in collection dataset I pass name of image).
How can I retrieve picture field name in main report?
You do not see the image because it does not have the proper Evaluation Time - it needs to be Band in your case.
The staticText does not support such setting, you need to convert it to a textField and set the same for the Evaluation Time property.
But even with the above suggestions you would still see the last value from your ImageDemoDataset subDataset. It is fine if that is what you want.
But if you want to display an image for each record in your subDataset, you would have to do it inside the table. If spacing was the issue, you could create a columnGroup and place the image in the groupFooter, isolating it below your main data.
EDIT: It seems that what you want is actually simpler and should not involve variables. You just need to reiterate over the same data source.
This can be done in 2 ways:
(1). Using the original ImageDataSource parameter:
<parameter name="ImageDataSource" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
have the table datasetRun's expression like so:
<dataSourceExpression><![CDATA[$P{ImageDataSource}.cloneDataSource()]]></dataSourceExpression>
Then create a list component under the table, with the same subDataset you used for the table and the initial data source expression:
<dataSourceExpression><![CDATA[$P{ImageDataSource}]]></dataSourceExpression>
and set its Print Order to Horizontal in the List tab from the list component properties. Make sure you also specify the Cell Width to be small enough to allow repeating items to flow horizontally.
Cloning the dataSource for the table will ensure that the table will not exhaust it, so that the list component will still be able to iterate over it.
(2). Instead of passing the JRBeanCollectionDataSource as a parameter, pass just the collection you created it with and have a parameter for that. This way you do not need to clone the dataSource anymore:
<parameter name="ImageCollection" class="java.util.Collection"/>
Then have the table datasetRun's expression like so:
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{ImageCollection})]]></dataSourceExpression>
Then create a list with the same subDataset you used for the table and use the dataSourceExpression from above. You should set up the list in the same way as in (1).

Jasper Report merging cells in jasper table results in unwanted coulmn

i am fairly new to jasper report. I need to merge cells in jasper table and i have managed some portion of it. See following image.
as u can see that the there is empty cells. I need a single cells instead of multiple empty cells. Can you guys help me with me. I am stuck. I am posting my jrxml
<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9c6d12ac-438a-4209-b92b-fe8357e9a0ab">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="2"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="medication" uuid="540773d1-98fb-48a3-9b89-a187c3e37e8a">
<queryString language="SQL">
<![CDATA[SELECT m.ID,m.medication_name,d.dose_time FROM medication m
LEFT JOIN dose_time d ON m.ID = d.medication_id;]]>
</queryString>
<field name="ID" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="medication_name" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="dose_time" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<group name="ID">
<groupExpression><![CDATA[$F{ID}]]></groupExpression>
</group>
</subDataset>
<queryString>
<![CDATA[select mdt.ID,mdt.medication_name,dt.dose_time from medication mdt left join dose_time dt on mdt.ID = dt.medication_id;]]>
</queryString>
<field name="ID" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="medication_name" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="dose_time" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement uuid="b80b6480-79a3-4c7a-b7e6-73e8df552d6a" key="table" style="table" x="0" y="0" width="555" height="125">
<printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="medication" uuid="966ad176-a042-4a9f-b4fe-3c5cf2c43370">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="90" uuid="1674ad29-29a8-47d3-9bf9-fb233d836dcc">
<jr:groupFooter groupName="ID">
<jr:cell height="0" rowSpan="1"/>
</jr:groupFooter>
<jr:columnHeader style="table_CH" height="32" rowSpan="1">
<staticText>
<reportElement uuid="1e2c5349-4cc9-4caf-9d7f-ac34dfbdb1b4" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[Medication Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement uuid="cfeb2bce-6f8d-413c-8f4e-cfbe61cc2d24" style="table_TD" x="0" y="0" width="90" height="30">
<printWhenExpression><![CDATA[$V{ID_COUNT}==1]]></printWhenExpression>
</reportElement>
<box leftPadding="0">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}+$F{medication_name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="193e3bc0-bdba-42ec-824a-cb0e7b37b7d1">
<jr:columnHeader style="table_CH" height="32" rowSpan="1">
<staticText>
<reportElement uuid="c165e681-8db2-49af-9046-e3db70bfe0cf" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[Doses Time]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<textField>
<reportElement uuid="78fff516-49ab-4e1d-aa06-4c97d48bad0d" x="0" y="0" width="90" height="30"/>
<textElement/>
<textFieldExpression><![CDATA[$F{dose_time}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
I see two possible solutions here:
Create a group band and group by "Medication Name" you will have empty cells but it will look cool :)
Use some SQL kung-fu with the function concat_ws() to get the "Doses Time" in the same field as a list.
Have fun and I hope it helps.