How to export to other sheets in excel from jasper report - jasper-reports

I have many subreports.
I want to have two other sheets in the excel file when generating the report from my application.
Tried this:
How to export to multiple sheets in excel from jasper report
How to show each subreport in a separate Excel sheet
https://www.youtube.com/watch?v=RJiGvwV_Ezs
In option 3 I get an error: dimensions are too large.
How to fix the error? Since the other options do not work
Here is my sample, master report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f -->
<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="1234" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="d4075463-97ae-475a-85c9-d750ec32590b">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="main"/>
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="true"/>
<property name="net.sf.jasperreports.page.break.no.pagination" value="apply"/>
<queryString language="SQL">
<![CDATA[select 1 as 'one']]>
</queryString>
<field name="one" class="java.lang.Integer">
<property name="com.jaspersoft.studio.field.name" value="one"/>
<property name="com.jaspersoft.studio.field.label" value="one"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="90" splitType="Prevent">
<textField textAdjust="StretchHeight">
<reportElement stretchType="ElementGroupHeight" x="0" y="0" width="555" height="30" uuid="49a2b283-488e-470e-a075-e014d0d0daf9"/>
<box>
<pen lineWidth="0.5"/>
</box>
<textFieldExpression><![CDATA[$F{one}]]></textFieldExpression>
</textField>
<textField textAdjust="StretchHeight">
<reportElement stretchType="ElementGroupHeight" x="0" y="60" width="555" height="30" uuid="d271a48a-99ba-4625-b3f0-bb04e03a9d1a"/>
<box>
<pen lineWidth="0.5"/>
</box>
<textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
</textField>
<break>
<reportElement x="0" y="37" width="100" height="1" uuid="0ac65ff7-6c8e-4ac6-b481-fdaf596d2415"/>
</break>
</band>
</detail>
</jasperReport>

Related

How can I use 2 columns in details in Jasper Studio? [duplicate]

This is my current jrxml file:
<?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="18199607-277f-4e05-b2ba-be2f5d89e7d5">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT
language.`id` AS language_id,
language.`name` AS language_name
FROM
`language` language]]>
</queryString>
<field name="language_id" class="java.lang.Long"/>
<field name="language_name" class="java.lang.String"/>
<title>
<band height="20" splitType="Stretch">
<staticText>
<reportElement uuid="662306ce-d3df-4306-b320-e89a92485da3" x="0" y="0" width="555" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true" isItalic="true" isUnderline="true" isStrikeThrough="false"/>
</textElement>
<text><![CDATA[Languages]]></text>
</staticText>
</band>
</title>
<detail>
<band height="41" splitType="Stretch">
<textField>
<reportElement uuid="1f1d2c1a-bafd-4095-9c7a-e0a48c20a82f" x="23" y="14" width="231" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{language_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1f1d2c1a-bafd-4095-9c7a-e0a48c20a82f" x="301" y="14" width="235" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{language_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="52cb1ba3-4bdd-4b18-877e-0c40f70d073d" x="0" y="14" width="23" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{language_id}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="52cb1ba3-4bdd-4b18-877e-0c40f70d073d" x="278" y="14" width="23" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{language_id}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
and this is my output:
and I need this:
So how can I show data in two columns from a list.
You should set report's property Print order (printOrder) value as Horizontal and the report's property Columns (columnCount) value as 2.
The sample
The jrxml file:
<?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="report39" language="groovy" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8ea55a1a-7e67-4906-b7be-7314b7bfa03d">
<queryString>
<![CDATA[SELECT id, name FROM PRODUCT]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="NAME" class="java.lang.String"/>
<detail>
<band height="61" splitType="Stretch">
<textField>
<reportElement uuid="ea1c8668-6d75-42da-9293-6cfd81297c03" x="0" y="0" width="24" height="61"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="652cf497-5bc2-4b62-b47a-23ec135cbfdf" x="24" y="0" width="176" height="61"/>
<textElement/>
<textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The report's design (in iReport):
The result will be (via preview in iReport):

Jasper report: detail band with several images with different heights

I want to create a report for print several map legends. Right now I can generate the report with the title, and for each legend there is the name and the image below.
But all images are being resized to have the same height: the height of the container band (Detail 2 band).
I want that each image have its own height and not the height of the band.
How can I have images with different heights?
My report is:
<?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="legend" pageWidth="555" pageHeight="802" columnWidth="185" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="6b65086b-74e0-4bec-834b-1b74d5ae2d31">
<property name="ireport.zoom" value="2.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="name" class="java.lang.String"/>
<field name="icon" class="java.awt.Image"/>
<field name="level" class="java.lang.Integer"/>
<detail>
<band height="25" splitType="Prevent">
<printWhenExpression><![CDATA[!$F{name}.equals("")]]></printWhenExpression>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="6" width="555" height="13" uuid="804c03e8-4edc-4888-8dba-0c683717bfeb"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
<band height="30" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<printWhenExpression><![CDATA[$F{icon} != null]]></printWhenExpression>
<image scaleImage="RetainShape">
<reportElement positionType="Float" stretchType="ContainerHeight" x="0" y="0" width="555" height="30" uuid="067c1436-8c32-4bd6-9fd2-db394dc7366a"/>
<imageExpression><![CDATA[$F{icon}]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>

How to split large frames

I've a jasper-report that has a detail band with the height of 1500px. My page height is 842px. There is a frame with the height of 940px inside this band.
Here is my jrxml-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-04T11:33:30 -->
<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="Template" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="fe0ec478-f3f0-4324-9feb-f143cc73c90f">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record" />
<detail>
<band height="1500" splitType="Stretch">
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="0" y="30" width="555" height="940" backcolor="#F5F9FF" uuid="917a9ec0-b801-49ca-93e7-5106f89868e9">
<property name="com.jaspersoft.studio.unit.width" value="pixel" />
</reportElement>
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#E3E3E3" />
</box>
</frame>
<staticText>
<reportElement x="0" y="0" width="555" height="30" uuid="303bc3ed-22ad-4f01-a7d1-c35e8b95ac77" />
<text>
<![CDATA[Static Text]]>
</text>
</staticText>
</band>
</detail>
</jasperReport>
After compilation I get following error:
The detail section, the page and column headers and footers and the margins do not fit the page height. --- net.sf.jasperreports.engine.design.JasperDesign
My first question is: why do I get this exception?
If I change the Split Type of the detail band to "Immediate" then I do not get the above error any more. After a few minutes I get OutOfMemoryError.
My third question: why do i get this error after changing the Split Type to "Immediate".
My third question is: how can i split my frame into 772px (after StaticText) and 168px on the top of the next page? I would like to display multiple Frames (with different heights; some of them very long) one after another.
you must change template size to your heigh
page size -> page heigh
try this code:
<?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="Template" pageWidth="595" pageHeight="1600" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="ireport.zoom" value="1.610510000000001"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<detail>
<band height="1500" splitType="Stretch">
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="0" y="30" width="555" height="940" backcolor="#F5F9FF">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#E3E3E3"/>
</box>
</frame>
<staticText>
<reportElement x="0" y="0" width="555" height="30"/>
<textElement/>
<text><![CDATA[
Static Text
]]></text>
</staticText>
</band>
</detail>
</jasperReport>
if you split page u can use:
<break><reportElement x="0" y="10" width="100" height="1"/></break>
page break in your 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="Template" pageWidth="595" pageHeight="1600" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="ireport.zoom" value="1.610510000000001"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<detail>
<band height="1500" splitType="Stretch">
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="0" y="84" width="555" height="886" backcolor="#F5F9FF">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#E3E3E3"/>
</box>
</frame>
<staticText>
<reportElement x="0" y="0" width="555" height="30"/>
<textElement/>
<text><![CDATA[firtst page]]></text>
</staticText>
<staticText>
<reportElement x="0" y="43" width="555" height="30"/>
<textElement/>
<text><![CDATA[next page]]></text>
</staticText>
<break>
<reportElement x="0" y="33" width="100" height="1"/>
</break>
</band>
</detail>
</jasperReport>

display column header in jasper reports

Trying to create a jasper report, I can see the data when I export to xls or csv. But column header is missing, not sure whats wrong with it, following is my report. Thanks in Advance.
<?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="scireport" language="groovy" printOrder="Horizontal" pageWidth="5000" pageHeight="792" whenNoDataType="AllSectionsNoDetail" columnWidth="4960" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="SQL">
<![CDATA[select PICKUP_DATE from SCI_PLDDATA_VIEW order by EVENT_TIMESTAMP DESC]]>
</queryString>
<field name="PICKUP_DATE" class="java.sql.Timestamp">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<group name="stopid">
<groupHeader>
<band height="50"/>
</groupHeader>
</group>
<columnHeader>
<band height="44" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="900" height="20"/>
<textElement>
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$R{jasper.PICKUP_DATE}]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="34" splitType="Stretch">
<textField isStretchWithOverflow="true" pattern="MM-dd-yyyy HH:mm" isBlankWhenNull="true">
<reportElement x="0" y="0" width="900" height="20"/>
<textElement/>
<textFieldExpression class="java.sql.Timestamp"><![CDATA[$F{PICKUP_DATE}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
You are fetching data from database , your value will come in field. You should use $F{} instead of $R{} in column header.

JasperReports: How to show data in two columns

This is my current jrxml file:
<?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="18199607-277f-4e05-b2ba-be2f5d89e7d5">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT
language.`id` AS language_id,
language.`name` AS language_name
FROM
`language` language]]>
</queryString>
<field name="language_id" class="java.lang.Long"/>
<field name="language_name" class="java.lang.String"/>
<title>
<band height="20" splitType="Stretch">
<staticText>
<reportElement uuid="662306ce-d3df-4306-b320-e89a92485da3" x="0" y="0" width="555" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true" isItalic="true" isUnderline="true" isStrikeThrough="false"/>
</textElement>
<text><![CDATA[Languages]]></text>
</staticText>
</band>
</title>
<detail>
<band height="41" splitType="Stretch">
<textField>
<reportElement uuid="1f1d2c1a-bafd-4095-9c7a-e0a48c20a82f" x="23" y="14" width="231" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{language_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1f1d2c1a-bafd-4095-9c7a-e0a48c20a82f" x="301" y="14" width="235" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{language_name}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="52cb1ba3-4bdd-4b18-877e-0c40f70d073d" x="0" y="14" width="23" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{language_id}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="52cb1ba3-4bdd-4b18-877e-0c40f70d073d" x="278" y="14" width="23" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{language_id}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
and this is my output:
and I need this:
So how can I show data in two columns from a list.
You should set report's property Print order (printOrder) value as Horizontal and the report's property Columns (columnCount) value as 2.
The sample
The jrxml file:
<?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="report39" language="groovy" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8ea55a1a-7e67-4906-b7be-7314b7bfa03d">
<queryString>
<![CDATA[SELECT id, name FROM PRODUCT]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="NAME" class="java.lang.String"/>
<detail>
<band height="61" splitType="Stretch">
<textField>
<reportElement uuid="ea1c8668-6d75-42da-9293-6cfd81297c03" x="0" y="0" width="24" height="61"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="652cf497-5bc2-4b62-b47a-23ec135cbfdf" x="24" y="0" width="176" height="61"/>
<textElement/>
<textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The report's design (in iReport):
The result will be (via preview in iReport):