Wednesday, 24 October 2018

Ireport Report How to Merge Table Rows With Repeated Values


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="Country" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="dbc44bea-4f8e-4072-9c94-8442f3093aa0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\fullPath\\to\\Your\\subreport\\"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[Select 'USA' as country from dual
union
Select 'INDIA' as country from dual]]>
</queryString>
<field name="COUNTRY" class="java.lang.String"/>
<background>
<band/>
</background>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="0" y="0" width="177" height="20" uuid="d4eb7868-2f74-4713-abca-a176c47927e1"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[COUNTRY]]></text>
</staticText>
<staticText>
<reportElement x="177" y="0" width="200" height="20" uuid="98cbcff7-6b24-43bd-a2df-39cc07e56487"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[STATE]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="177" height="20" uuid="1bbab3e7-f8a3-48c9-b28e-2a6d2a68b755"/>
<box topPadding="0" leftPadding="0">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{COUNTRY}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="177" y="0" width="200" height="20" uuid="859cccb4-100e-4c26-b19b-82c2cbdfa088"/>
<subreportParameter name="p_country">
<subreportParameterExpression><![CDATA[$F{COUNTRY}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["C:\\subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>



Subreport

<?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="country_subreport" pageWidth="200" pageHeight="500" columnWidth="200" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="c9795fb7-39e0-4aa6-8926-2f019c4af84e">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="p_country" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[Select * from
(
Select 'USA' as country, 'Alabama'  as state from dual
union
Select 'INDIA' as country, 'Punjab' as state from dual
union
Select 'USA' as country, 'Texas'  as state from dual
union
Select 'INDIA' as country, 'Haryana' as state from  dual
union
Select 'USA' as country,'Washington'  as state from dual
union
Select 'INDIA' as country, 'Karnataka'  as state from dual
) where country = $P{p_country}]]>
</queryString>
<field name="COUNTRY" class="java.lang.String"/>
<field name="STATE" class="java.lang.String"/>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="200" height="20" uuid="dc0a9dda-b940-4752-ad91-31420c4ce729"/>
<box topPadding="2" leftPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{STATE}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>





No comments:

Post a Comment