How to merge cells in same column [duplicate] - jasper-reports

In jrxml design for my report, I have a column in my detail section that is printing same thing for a specific group. For Example, if i have a country column USA and the next column contains its states. Country USA repeats for each entry . So i need to merge the country cells has USA value. I need to merge all the cells of column has same value and should display it as a single cell and it should align its text vertically and horizontally center. Anybody help me how can i achieve this by using jrxml?
Everything is in the Detail band.
I am working to get a report like in the below picture
UPDATED:
From Peter's answer I have one doubt, if my xml is like:
<report>
<row1>
<country>INDIA</country>
<state>Haryana</state>
</row1>
<row2>
<country>INDIA</country>
<state>Punjab</state>
</row2>
<row3>
<country>INDIA</country>
<state>Maharashtra</state>
</row3>
</report>
How can I create the report if my xml is like above?

You can fairly easy achieve text vertically aligned at top by using isPrintRepeatedValues="false", setting borders correctly (only top, using empty cell with only left, adding line to columnFooter).
To achieve "text vertically aligned at center" use a subreport for the other columns and set stretchType="RelativeToBandHeight" on your rowspan column.
Note you need in this case change your datasource (main report, country by country, subreport all states relative to country)
EDIT: Comment: This not works in detail band. Petter – #Tinoy Malayil.
I include a runnable example for text vertically aligned at center:
Datasource xml:
<report>
<country>
<name>INDIA</name>
<states>
<state>Haryana</state>
<state>Punjab</state>
<state>Maharashtra</state>
<state>Karnataka</state>
<state>TamilNadu</state>
</states>
</country>
<country>
<name>USA</name>
<states>
<state>Alabama</state>
<state>Washington</state>
<state>Alaska</state>
<state>Texas</state>
</states>
</country>
</report>
Main report:, country.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="Country" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="dbc44bea-4f8e-4072-9c94-8442f3093aa0">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\fullPath\\to\\Your\\subreport\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[report/country]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<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{name}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="177" y="0" width="200" height="20" uuid="6314908a-006d-4a5b-9137-a056eb205529"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/country/states/state")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "country_subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
subreport, country_subreport.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="country_subreport" language="java" 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"/>
<queryString language="xPath">
<![CDATA[/report/country/states/state]]>
</queryString>
<field name="state" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<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>

Related

The vertical alignment is not working for several merged text fields (isPrintRepeatedValues=false) [duplicate]

In jrxml design for my report, I have a column in my detail section that is printing same thing for a specific group. For Example, if i have a country column USA and the next column contains its states. Country USA repeats for each entry . So i need to merge the country cells has USA value. I need to merge all the cells of column has same value and should display it as a single cell and it should align its text vertically and horizontally center. Anybody help me how can i achieve this by using jrxml?
Everything is in the Detail band.
I am working to get a report like in the below picture
UPDATED:
From Peter's answer I have one doubt, if my xml is like:
<report>
<row1>
<country>INDIA</country>
<state>Haryana</state>
</row1>
<row2>
<country>INDIA</country>
<state>Punjab</state>
</row2>
<row3>
<country>INDIA</country>
<state>Maharashtra</state>
</row3>
</report>
How can I create the report if my xml is like above?
You can fairly easy achieve text vertically aligned at top by using isPrintRepeatedValues="false", setting borders correctly (only top, using empty cell with only left, adding line to columnFooter).
To achieve "text vertically aligned at center" use a subreport for the other columns and set stretchType="RelativeToBandHeight" on your rowspan column.
Note you need in this case change your datasource (main report, country by country, subreport all states relative to country)
EDIT: Comment: This not works in detail band. Petter – #Tinoy Malayil.
I include a runnable example for text vertically aligned at center:
Datasource xml:
<report>
<country>
<name>INDIA</name>
<states>
<state>Haryana</state>
<state>Punjab</state>
<state>Maharashtra</state>
<state>Karnataka</state>
<state>TamilNadu</state>
</states>
</country>
<country>
<name>USA</name>
<states>
<state>Alabama</state>
<state>Washington</state>
<state>Alaska</state>
<state>Texas</state>
</states>
</country>
</report>
Main report:, country.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="Country" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="dbc44bea-4f8e-4072-9c94-8442f3093aa0">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\fullPath\\to\\Your\\subreport\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[report/country]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<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{name}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="177" y="0" width="200" height="20" uuid="6314908a-006d-4a5b-9137-a056eb205529"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/country/states/state")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "country_subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
subreport, country_subreport.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="country_subreport" language="java" 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"/>
<queryString language="xPath">
<![CDATA[/report/country/states/state]]>
</queryString>
<field name="state" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<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>

How to merge cells in same column, apply rowspan?

In jrxml design for my report, I have a column in my detail section that is printing same thing for a specific group. For Example, if i have a country column USA and the next column contains its states. Country USA repeats for each entry . So i need to merge the country cells has USA value. I need to merge all the cells of column has same value and should display it as a single cell and it should align its text vertically and horizontally center. Anybody help me how can i achieve this by using jrxml?
Everything is in the Detail band.
I am working to get a report like in the below picture
UPDATED:
From Peter's answer I have one doubt, if my xml is like:
<report>
<row1>
<country>INDIA</country>
<state>Haryana</state>
</row1>
<row2>
<country>INDIA</country>
<state>Punjab</state>
</row2>
<row3>
<country>INDIA</country>
<state>Maharashtra</state>
</row3>
</report>
How can I create the report if my xml is like above?
You can fairly easy achieve text vertically aligned at top by using isPrintRepeatedValues="false", setting borders correctly (only top, using empty cell with only left, adding line to columnFooter).
To achieve "text vertically aligned at center" use a subreport for the other columns and set stretchType="RelativeToBandHeight" on your rowspan column.
Note you need in this case change your datasource (main report, country by country, subreport all states relative to country)
EDIT: Comment: This not works in detail band. Petter – #Tinoy Malayil.
I include a runnable example for text vertically aligned at center:
Datasource xml:
<report>
<country>
<name>INDIA</name>
<states>
<state>Haryana</state>
<state>Punjab</state>
<state>Maharashtra</state>
<state>Karnataka</state>
<state>TamilNadu</state>
</states>
</country>
<country>
<name>USA</name>
<states>
<state>Alabama</state>
<state>Washington</state>
<state>Alaska</state>
<state>Texas</state>
</states>
</country>
</report>
Main report:, country.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="Country" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="dbc44bea-4f8e-4072-9c94-8442f3093aa0">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\fullPath\\to\\Your\\subreport\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[report/country]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<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{name}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="177" y="0" width="200" height="20" uuid="6314908a-006d-4a5b-9137-a056eb205529"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/country/states/state")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "country_subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
subreport, country_subreport.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="country_subreport" language="java" 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"/>
<queryString language="xPath">
<![CDATA[/report/country/states/state]]>
</queryString>
<field name="state" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<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>

Multiple rows inside a single column in jasper table

I am just a beginner in jasper report and i am stuck for a few days in a problem.
I have two tables
Medication {ID,medication_name}
and
dose_time{ID,medication_id,dose_time}
Applying
SELECT m.id,m.medication_name,d_t.dose_time FROM medication `m`
LEFT JOIN dose_time d_t ON m.id=d_t.medication_id;
gives me three result
Now what i want is following jasper report
But i could stuck and can generate only following jasper format
My jrxml file is as follow
<?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="PracticeReport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="67dfb372-a5be-403b-9007-61ab07fe88e7">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="Medication" uuid="1cccb880-701b-491e-8094-c133d4bd3819">
<queryString>
<![CDATA[SELECT m.id,m.medication_name,d_t.dose_time FROM medication `m`
LEFT JOIN dose_time d_t ON m.id=d_t.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>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement uuid="8bc54002-3e51-4bd6-8801-9856ef627b99" x="154" y="28" width="240" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Practicing Jasper]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement uuid="5976a679-e65a-4880-a9e7-74fd65f9e80d" key="" isPrintRepeatedValues="false" 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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Medication" uuid="5f6c54e4-9c5c-4120-8ac7-32793ec39d00"/>
<jr:column width="232" uuid="c5a6dca0-3be4-422f-8f13-4462d2e4caee">
<jr:detailCell height="124" rowSpan="1">
<textField>
<reportElement uuid="080e50f3-23a0-4bf2-8d6f-b63618dfdc51" isPrintRepeatedValues="false" x="0" y="0" width="232" height="124"/>
<box>
<pen lineWidth="0.75"/>
<topPen lineWidth="0.75"/>
<leftPen lineWidth="0.75"/>
<bottomPen lineWidth="0.75"/>
<rightPen lineWidth="0.75"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{id} + ","+$F{medication_name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="232" uuid="b7bef864-31db-4b77-a929-a0d59e754b36">
<jr:detailCell height="124" rowSpan="1">
<textField>
<reportElement uuid="7b3c68b6-6048-4690-b8e7-14a286f94297" x="0" y="0" width="232" height="124"/>
<box>
<pen lineWidth="0.75"/>
<topPen lineWidth="0.75"/>
<leftPen lineWidth="0.75"/>
<bottomPen lineWidth="0.75"/>
<rightPen lineWidth="0.75"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{dose_time}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Please guys i need your help.
You can use a crosstab for that. Go to Window and click on Palette. Than the palette will appear right. Finally, drag 'crosstab' to the summary section and fill in the wizard.
This might be of some help https://community.jaspersoft.com/wiki/how-merge-table-rows-repeated-values
In this solution, 2 datasets are used, the first dataset groups the data while the second dataset is used to create a table which is embedded in a band.
Edit: I applied another approach to do this. I used a table for the entire thing. The first column of the table is for the medicine and contains a textfield. The second column of the table is for the timing. It is a sub report and the sub report in turn contains another table with the timing.
I didn't use SQL but created a manual data in java. Here is my java code.
import static com.vroozi.api.requests.util.JasperUtils.compileJrxmlToJasper;
import com.vroozi.api.requests.util.JasperUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.springframework.stereotype.Service;
#Service
public class PDFServiceImpl {
public String generate() throws JRException {
final String format = DATE_TIME_FORMAT.format(new Date());
final String outputFileName = String.format("PO_%s_%s_PDF.pdf", "rajshree", format);
final String purchaseReportsPath = "/home/oem";
Map<String, Object> parameters = new HashMap<>();
Map<String, Object> cetamolMap = new HashMap<>();
cetamolMap.put("medicine", "Cetamol");
Map<String, Object> painKillerMap = new HashMap<>();
painKillerMap.put("medicine", "Pain killer");
List<Map<String, Object>> medicineMapList = Arrays.asList(cetamolMap, painKillerMap);
Map<String, Object> time1 = new HashMap<>();
time1.put("time", "11 a.m.");
Map<String, Object> time2 = new HashMap<>();
time2.put("time", "2 p.m.");
List<Map<String, Object>> timeMapList = Arrays.asList(time1, time2);
cetamolMap.put("timeList", new JRBeanCollectionDataSource(timeMapList));
painKillerMap.put("timeList", new JRBeanCollectionDataSource(new ArrayList<>()));
// Adding subreport for each medicine
cetamolMap.put("timeTableSubReport",
compileJrxmlToJasper("/subreport.jrxml"));
painKillerMap.put("timeTableSubReport",
compileJrxmlToJasper("/reports/subreport.jrxml"));
parameters.put("medicineMapList", new JRBeanCollectionDataSource(medicineMapList));
return JasperUtils.generatePdfReport("/reports/report.jrxml",
parameters, purchaseReportsPath, outputFileName);
}
}
Here is the "report.jrxml"
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="catalogPOCR" pageWidth="559" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="559" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" whenResourceMissingType="Empty" uuid="42c67c01-6232-438f-8149-de04399dfcd2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="org.apache.commons.collections.CollectionUtils"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<style name="table 1">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
<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>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#FFFFFF"/>
</conditionalStyle>
</style>
<subDataset name="Table LineItems" uuid="183918c2-b66e-4347-ae7b-e891ab0a1d88">
<field name="medicine" class="java.lang.String"/>
<field name="timeTableSubReport" class="net.sf.jasperreports.engine.JasperReport"/>
<field name="timeList" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
</subDataset>
<subDataset name="Dataset1" uuid="183918c2-b66e-4347-ae7b-e891ab0a1d88">
<field name="order" class="java.lang.String"/>
</subDataset>
<parameter name="medicineMapList" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<parameter name="timeTableSubReport" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<detail>
<band height="170">
<componentElement>
<reportElement key="table 1" style="table 1" positionType="Float" x="0" y="0" width="504" height="70" uuid="eb4057df-dd6a-40dd-870e-baac8c8afe17">
<property name="local_mesure_unitwidth" value="inch"/>
<property name="com.jaspersoft.studio.unit.width" value="inch"/>
<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="Table LineItems" uuid="8a44aec8-cdd4-4be3-b47a-620e00bb910a">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{medicineMapList}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="70" uuid="baa7f786-d12a-4234-b9d7-faef6c9f25df">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<box>
<pen lineWidth="0.0"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="70" height="20" uuid="5f84b7ac-c2fe-4426-b91f-6714b470a2bc"/>
<box topPadding="5" leftPadding="2" bottomPadding="5" rightPadding="2">
<topPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="8" isBold="false"/>
<paragraph rightIndent="4"/>
</textElement>
<textFieldExpression><![CDATA[$F{medicine}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="70" uuid="baa7f786-d12a-4234-b9d7-faef6c9f25df">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<box>
<pen lineWidth="0.0"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<frame>
<reportElement positionType="Float" isPrintRepeatedValues="false" x="0" y="0" width="50" height="20" isRemoveLineWhenBlank="true" isPrintInFirstWholeBand="true" uuid="62f0ab9e-28c4-4a58-935b-f98d26d600e3">
<property name="ShowOutOfBoundContent" value="false"/>
</reportElement>
<subreport>
<reportElement positionType="Float" x="0" y="0" width="50" height="20" uuid="48a7bbe4-b8ce-4a0d-a6e1-6ddd288e5602"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportParameter name="timeList">
<subreportParameterExpression><![CDATA[$F{timeList}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
<subreportExpression><![CDATA[$F{timeTableSubReport}]]></subreportExpression>
</subreport>
</frame>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Here is the subreport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<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="timeTableSubReport" pageWidth="559" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="559" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" whenResourceMissingType="Empty" uuid="42c67c01-6232-438f-8149-de04399dfcd2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="org.apache.commons.collections.CollectionUtils"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<style name="table 1">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
<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>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.0" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#FFFFFF"/>
</conditionalStyle>
</style>
<subDataset name="Table LineItems" uuid="183918c2-b66e-4347-ae7b-e891ab0a1d88">
<field name="time" class="java.lang.String"/>
</subDataset>
<parameter name="timeList" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<detail>
<band height="70">
<componentElement>
<reportElement key="table 1" style="table 1" positionType="Float" x="0" y="0" width="504" height="70" uuid="eb4057df-dd6a-40dd-870e-baac8c8afe17">
<property name="local_mesure_unitwidth" value="inch"/>
<property name="com.jaspersoft.studio.unit.width" value="inch"/>
<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="Table LineItems" uuid="8a44aec8-cdd4-4be3-b47a-620e00bb910a">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{timeList}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="70" uuid="baa7f786-d12a-4234-b9d7-faef6c9f25df">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<box>
<pen lineWidth="0.0"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.0"/>
</box>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="70" height="20" uuid="5f84b7ac-c2fe-4426-b91f-6714b470a2bc"/>
<box topPadding="5" leftPadding="2" bottomPadding="5" rightPadding="2">
<topPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="8" isBold="false"/>
<paragraph rightIndent="4"/>
</textElement>
<textFieldExpression><![CDATA[$F{time}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
The output looks like this
P.S. I didn't really pay attention to styling here. Hope this helps someone although I am 7 years late.

Jasper Report: CSV DataSource in table component

I have a requirement where I have to read CSV file and prepare a report in Jasper. I am able to use CSV data source in regular text field. But when I add a table to Detail or Summary section it expects a new Data Set to be created. I created it successfully but when the report runs it is not able to get the data from CSV data source, I am getting a blank report. The same thing works if I use Database instead of CSV. Is there a bug in Jasper.
I had the same problem. To fix it, go to the table component, right-click, then "Edit data source", choice "Connection data source expression" and write:
((net.sf.jasperreports.engine.data.JRCsvDataSource)$P{REPORT_DATA_SOURCE})
Below is a sample JRXML which shows how to use a CSV data source in the table component.
Please note that you need to name the fields in the sub dataset "COLUMN_" + the column index. This way in JRCsvDataSource#getFieldValue your field will be located correctly without having to add a row for column headers in the CSV file.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0 -->
<!-- 2016-08-23T13:06:06 -->
<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="SimpleReportWithTable" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b32b572d-c517-48ba-a44e-3402966e9932">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="SimpleCsvDataAdapter"/>
<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>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#FBFDFF"/>
</conditionalStyle>
</style>
<subDataset name="Dataset1" uuid="76efa803-c263-4538-a39a-8ddb1712e58a">
<field name="COLUMN_0" class="java.lang.String"/>
<field name="COLUMN_1" class="java.lang.String"/>
<field name="COLUMN_2" class="java.lang.String"/>
<field name="COLUMN_3" class="java.lang.String"/>
<field name="COLUMN_4" class="java.lang.String"/>
<field name="COLUMN_5" class="java.lang.String"/>
<field name="COLUMN_6" class="java.lang.String"/>
<field name="COLUMN_7" class="java.lang.String"/>
<field name="COLUMN_8" class="java.lang.String"/>
</subDataset>
<parameter name="CSV_DATA_SOURCE" class="net.sf.jasperreports.engine.data.JRCsvDataSource" isForPrompting="false">
<defaultValueExpression><![CDATA[new net.sf.jasperreports.engine.data.JRCsvDataSource("path_to_csv_file")]]></defaultValueExpression>
</parameter>
<summary>
<band height="70" splitType="Stretch">
<componentElement>
<reportElement x="0" y="10" width="200" height="60" uuid="a5c67e1f-1b96-4044-b4d2-ba9da8502bab">
<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="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="Dataset1" uuid="7738bf3c-ecda-4864-9804-c6319de53296">
<dataSourceExpression><![CDATA[$P{CSV_DATA_SOURCE}]]></dataSourceExpression>
</datasetRun>
<jr:column width="66" uuid="5c06dacd-68b4-4972-87e9-45dcbf181cbd">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="3ecb3cf8-02f5-4783-b407-9d36a3b76a9e"/>
<text><![CDATA[Row 1]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="21db9e1b-c129-40f6-afd5-c8fc9b939112"/>
<textFieldExpression><![CDATA[$F{COLUMN_0}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="66" uuid="45989e75-9ad1-4a48-ae63-ddaf380930e7">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="392ead1f-fd67-431c-8da6-3cf3dad9728d"/>
<text><![CDATA[Row 2]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="1a1fb7ba-cec2-44f7-bdc7-3a3887302fb0"/>
<textFieldExpression><![CDATA[$F{COLUMN_1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="66" uuid="128a9867-c221-4862-a9ac-f5cc99e394f1">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="033b57f1-b3dd-4909-8ed7-84c99f92eccd"/>
<text><![CDATA[Row 3]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="0d2027c4-e761-4e14-b093-31be3c0493e0"/>
<textFieldExpression><![CDATA[$F{COLUMN_2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>
For table component you have to create new data source, What you have to do drag a table component and click on "New Dataset" and select CSV dataset from the connection/Data Sources drop down list.

I-Report 4.1.1 static text element issue

Hello everyone,
I am using static text element in my column band.In that element i have aligned my text vertically in center of the element.I need the same alignment in the excel file when i am exporting the jrxml file.But i am getting the default horizontal alignment ..Please provide me with the solution
You can try this sample:
<?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="test_excel_columns" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT ID, FIRSTNAME, LASTNAME, STREET, CITY FROM ADDRESS]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="FIRSTNAME" class="java.lang.String"/>
<field name="LASTNAME" class="java.lang.String"/>
<field name="STREET" class="java.lang.String"/>
<field name="CITY" class="java.lang.String"/>
<columnHeader>
<band height="35" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="75" height="35"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement x="75" y="0" width="271" height="35"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Name]]></text>
</staticText>
<staticText>
<reportElement x="346" y="0" width="100" height="35"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Street]]></text>
</staticText>
<staticText>
<reportElement x="446" y="0" width="100" height="35"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="0.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[City]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="75" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="75" y="0" width="271" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{FIRSTNAME} + " " + $F{LASTNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="346" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{STREET}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="446" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The output in Excel preview is:
My iReport version is 4.1.3.