Jasper report: detail band with several images with different heights - jasper-reports

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>

Related

New/different page for different organization IDs in Jaspersoft report

I'm looking for any suggestions on how to print a new/different page for different organization IDs. I created a jaspersoft grouping and was thinking of adding a print when expression to the organization ID group header. Would that be the way to go? Can anyone help me with the expression that I would need for that?
"Start New Page" (isStartNewPage="true") in the Appearance tab of the Properties for the Group Header is all that is necessary to start on a new page for every new group. Group Expression for your situation would simply be something like $F{organizationID}.
Here's an example that groups on $F{city}, lists $F{CustomerID} and starts a new page for every new $F{city}:
<?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="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="62ac07f5-f11e-4179-aedb-a42e850c1ea8">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="northwind"/>
<queryString language="jsonql">
<![CDATA[Northwind.Customers]]>
</queryString>
<field name="City" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="City"/>
<fieldDescription><![CDATA[City]]></fieldDescription>
</field>
<field name="CustomerID" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="CustomerID"/>
<fieldDescription><![CDATA[CustomerID]]></fieldDescription>
</field>
<group name="City" isStartNewPage="true">
<groupExpression><![CDATA[$F{City}]]></groupExpression>
</group>
<columnHeader>
<band height="12" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="12" uuid="bdf3f7ab-bf1d-451e-a2ad-831a551ce388"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Company Name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="12" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="12" uuid="c7bcc5aa-8051-48ad-a0d6-fe27c68da204"/>
<textFieldExpression><![CDATA[$F{CustomerID}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

How to export to other sheets in excel from jasper report

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>

How to evaluate a jasper report variable when there is no data?

I have a report that using a parameter to determine the report title. It is displaying null when there is no data. I've tried changing the variable $V{reportName} Evaluation Time, but no luck. Can anybody help me?
Thanks.
PS: It is using mssql data adapter and the current querystring does not return any row. To return rows, change 2=1 to 1=1.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 5.6.1.final using JasperReports Library version 5.6.1 -->
<!-- 2017-05-02T07:59:20 -->
<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="Evaluate" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a736ce53-7e76-4194-9086-96d2270a6250">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="SYDPC1744-EXPRESSR2"/>
<parameter name="ReportType" class="java.lang.String">
<defaultValueExpression><![CDATA["B"]]></defaultValueExpression>
</parameter>
<queryString language="SQL">
<![CDATA[select Col1 from (values (1),(2)) as a(Col1) where 2=1]]>
</queryString>
<field name="Col1" class="java.lang.Integer"/>
<variable name="ReportName" class="java.lang.String">
<variableExpression><![CDATA[$P{ReportType}.equals("A")? $V{reportTitleA}:$V{reportTitleB}]]></variableExpression>
</variable>
<variable name="reportTitleA" class="java.lang.String">
<variableExpression><![CDATA["Report A"]]></variableExpression>
</variable>
<variable name="reportTitleB" class="java.lang.String">
<variableExpression><![CDATA["Report Other"]]></variableExpression>
</variable>
<pageHeader>
<band height="49" splitType="Stretch">
<textField evaluationTime="Report">
<reportElement x="0" y="0" width="390" height="20" uuid="98c519b9-7350-4cd6-a71e-f2fb1c0e7b80"/>
<textFieldExpression><![CDATA[$V{ReportName}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="14" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="15" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<textField>
<reportElement x="0" y="0" width="100" height="14" uuid="82ab5741-1138-4173-88f5-42ef07a6cb9f">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textFieldExpression><![CDATA[$F{Col1}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Your problem was setting the <textFieldExpression>
and not the <initialValueExpression>.
The <textFieldExpression> is used for calculation. Only use it for calculation!
The <initialValueExpression> is used for your initial value of this variable.
When there is no data jasperreports won't go through the calculation expression as there is no way, you could calculate using no data at all.
So just use the initial value expression...
Chaning the evaluation time of the element has no benefits at all in this case, so you can just skip it.
Also keep in mind, that by using a good order for your variables you can avoid many errors.
Here is the working code (excerpt):
<variable name="reportTitleA" class="java.lang.String">
<initialValueExpression><![CDATA["Report A"]]></initialValueExpression>
</variable>
<variable name="reportTitleB" class="java.lang.String">
<initialValueExpression><![CDATA["Report Other"]]></initialValueExpression>
</variable>
<variable name="ReportName" class="java.lang.String">
<initialValueExpression><![CDATA[$P{ReportType}.equals("A")? $V{reportTitleA}:$V{reportTitleB}]]></initialValueExpression>
</variable>
<pageHeader>
<band height="49" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="390" height="20" uuid="98c519b9-7350-4cd6-a71e-f2fb1c0e7b80"/>
<textFieldExpression><![CDATA[$V{ReportName}]]></textFieldExpression>
</textField>
</band>
</pageHeader>

How to split to new page when isIgnorePagination?

Using Jaspersoft studio 6.2.
A main report with detail and summary bands. A sub report in the summary band of the main report. The main report itself (when without the subreport) will split into two pages, so I checked isIgnorePagination and the main report (when without subreport) comes out as single page.
The subreport itself split to 9 pages by default, when I checked isIgnorePagination it comes out as one single page. Fine. When I put the subreport in the main report with all the settings above, it comes out as one single page. How can I make the main report in one page and subreport in another page (so two pages in total)?
EDIT
Tried break component, it works but there is still a problem. The page height of the main report has to be set to be big enough to include both main report and subreport, otherwise there will be more than 2 pages, but that will leave too much blank at the bottom of the main report. Below is an example to show what I meant.
main report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-04-26T16:13:43 -->
<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="test11" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ce9d78e1-7194-4754-aaf9-93e871d2a5cf">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<queryString>
<![CDATA[select 1 as a
union all select 2 as a]]>
</queryString>
<field name="a" class="java.lang.Integer"/>
<variable name="Total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{a}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="50">
<staticText>
<reportElement x="54" y="0" width="100" height="30" uuid="e9116c0f-c827-4cb3-95d1-9155f4be7cb7"/>
<text><![CDATA[a]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="49" splitType="Stretch">
<textField>
<reportElement x="50" y="10" width="100" height="30" uuid="79fa53fa-48e2-43d0-96a4-0cda54e95c25"/>
<textFieldExpression><![CDATA[$F{a}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="297" splitType="Stretch">
<textField>
<reportElement mode="Opaque" x="52" y="16" width="100" height="30" backcolor="#C4E5F6" uuid="2a393151-947e-4f1d-ab24-e456ce56bd19"/>
<textFieldExpression><![CDATA[$V{Total}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="62" y="97" width="200" height="200" uuid="b342cbae-597b-4ca5-b00d-3a4d047910f8"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["test12.jasper"]]></subreportExpression>
</subreport>
<break>
<reportElement x="0" y="60" width="619" height="1" uuid="ccc2155d-6a2e-4c23-a972-88bb871cb17d"/>
</break>
</band>
</summary>
</jasperReport>
sub report
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-04-26T16:14:10 -->
<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="test12" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3601f813-f6da-4105-a4d8-5c1ee1dd54d4">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
<queryString>
<![CDATA[select 10 as col
union all select 20 as col]]>
</queryString>
<field name="col" class="java.lang.Integer"/>
<variable name="total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{col}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="73" y="0" width="100" height="30" uuid="5f2cfa26-c7ab-413e-94cf-80c1f1b288eb"/>
<text><![CDATA[col]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="73" y="90" width="100" height="30" uuid="3af983fb-00e2-4bb9-9e91-2d2214ca95d7"/>
<textFieldExpression><![CDATA[$F{col}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="49" splitType="Stretch">
<textField>
<reportElement mode="Opaque" x="74" y="19" width="100" height="30" backcolor="#FFCC33" uuid="b333fb92-8aa8-4f00-9a1a-db24657d5521"/>
<textFieldExpression><![CDATA[$V{total}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
There is a break in the main report, this works fine, 2 pages one for the main report and one for the sub report, but the main report leaves too much blank at the bottom, if I reduce the height of the main report (e.g. to 400 pixel), there will be more than 2 pages. Is it possible to get just 2 pages without too much blank?
To achieve different size for each page you need to use the attribute, isIgnorePagination="true" on the jasperReport tag.
When isIgnorePagination is true the break element is ignored by default you need to enabled it by setting this property net.sf.jasperreports.page.break.no.pagination to apply
ignore - page breaks are ignored in non paginated reports. (default) apply -
page breaks are honoured in non paginated reports.
<property name="net.sf.jasperreports.page.break.no.pagination" value="apply"/>
This will enable the break component and you can manuale break to new page using
<break>
<reportElement x="0" y="0" width="100" height="1" uuid="604c65b5-1127-4874-a63c-9b1a98dbf25c"/>
</break>

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.