Grouping Consecutive Numbers on a Dataset in JasperReports (iReport) - java

I have a query in my jasper report and one of its result set generated by the user-given inputs might be those datum stated below:
memberId stockNo refineryCode constantSerialNo serialNo
45 1 IAR A- 98729
45 1 IAR A- 98730
45 1 IAR A- 98731
45 1 IAR A- 98733
45 1 IAR A- 98734
45 1 IAR A- 98736
45 1 IAR A- 98737
45 1 IAR A- 98738
45 1 IAR A- 98739
And I want to display those datum on one line if the serialNo's are consecutive. So if I wanna display the above datum in the report, I have to display them in the below stated manner:
memberId stockNo refineryCode constantSerialNo serialNo
45 1 IAR A- 98729 - 98731
45 1 IAR A- 98733 - 98734
45 1 IAR A- 98736 - 98739
I know that there might be some solutions using cursor on the sql or using ORM in an OOP language like Java and sending to the jasper report. However, just out of curiosity I'd like to ask whether there may be a dynamic solution using iReport's Expressions or Groups or any other thing that didn't come to my mind now which can make my life easier.

Here is one way to do it, assuming serialNo is some sort of numerical value and not a String.
The dataset of the sql query result has to be ordered by serialNo, like you have shown above.
Create a Report Group with the following group expression: $V{GroupCount} == new BigDecimal(0) ? $F{serialNo}:$F{serialNo}.subtract($V{GroupCount}). This will create a new group every time there is a gap in the serialNo sequence.
Create a variable GroupCount that counts the number of consecutive serialNo values in the current group. This variable is used to keep track of what the next expected serialNo value is.
Create a variable StartRange that will hold the start value for a given range of consecutive serialNo values. The value should reset on the start of a new group and have the following value: $V{GroupCount}.intValue() == 1 ? $F{ID}:$V{StartRange}.
Set the Evaluation Time value of the serialNo field to be ReportGroup. Put the following value in it: $V{StartRange}+" - " + $F{serialNo}.
Change the Print When Expression of the Detail band to the followng: new Boolean($V{GroupCount}.intValue() == 1).
I have posted complete jrxml code below.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="Group_By_Consecutive" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false">
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />
<queryString>
<![CDATA[select 1 as id, 'Name 1' as name from dual union all
select 2 as id, 'Name 2' as name from dual union all
select 3 as id, 'Name 3' as name from dual union all
select 4 as id, 'Name 4' as name from dual union all
select 6 as id, 'Name 6' as name from dual union all
select 7 as id, 'Name 7' as name from dual union all
select 8 as id, 'Name 8' as name from dual union all
select 9 as id, 'Name 9' as name from dual union all
select 10 as id, 'Name 10' as name from dual union all
select 11 as id, 'Name 11' as name from dual union all
select 14 as id, 'Name 14' as name from dual union all
select 15 as id, 'Name 15' as name from dual union all
select 16 as id, 'Name 16' as name from dual union all
select 17 as id, 'Name 17' as name from dual union all
select 23 as id, 'Name 23' as name from dual union all
select 24 as id, 'Name 24' as name from dual union all
select 25 as id, 'Name 25' as name from dual union all
select 26 as id, 'Name 26' as name from dual union all
select 27 as id, 'Name 27' as name from dual union all
select 28 as id, 'Name 28' as name from dual]]>
</queryString>
<field name="ID" class="java.math.BigDecimal" />
<field name="NAME" class="java.lang.String" />
<variable name="GroupCount" class="java.math.BigDecimal" resetType="Group" resetGroup="Consecutive" calculation="Count">
<variableExpression>
<![CDATA[$F{ID}]]>
</variableExpression>
<initialValueExpression>
<![CDATA[new BigDecimal(0)]]>
</initialValueExpression>
</variable>
<variable name="StartRange" class="java.math.BigDecimal" resetType="Report" calculation="Nothing">
<variableExpression>
<![CDATA[$V{GroupCount}.intValue() == 1 ? $F{ID}:$V{StartRange}]]>
</variableExpression>
</variable>
<group name="Consecutive">
<groupExpression>
<![CDATA[$V{GroupCount} == new BigDecimal(0) ? $F{ID}:$F{ID}.subtract($V{GroupCount})]]>
</groupExpression>
<groupHeader>
<band height="0" isSplitAllowed="true"></band>
</groupHeader>
<groupFooter>
<band height="0" isSplitAllowed="true"></band>
</groupFooter>
</group>
<background>
<band height="0" isSplitAllowed="true"></band>
</background>
<title>
<band height="0" isSplitAllowed="true"></band>
</title>
<pageHeader>
<band height="0" isSplitAllowed="true"></band>
</pageHeader>
<columnHeader>
<band height="18" isSplitAllowed="true">
<staticText>
<reportElement x="0" y="0" width="200" height="18" key="staticText-1" />
<box></box>
<textElement>
<font />
</textElement>
<text>
<![CDATA[serialNo]]>
</text>
</staticText>
<staticText>
<reportElement x="200" y="0" width="100" height="18" key="staticText-3" />
<box></box>
<textElement>
<font />
</textElement>
<text>
<![CDATA[Name]]>
</text>
</staticText>
<staticText>
<reportElement x="300" y="0" width="100" height="18" key="staticText-4" />
<box></box>
<textElement>
<font />
</textElement>
<text>
<![CDATA[MetaData(Ignore)]]>
</text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="18" isSplitAllowed="true">
<printWhenExpression>
<![CDATA[new Boolean($V{GroupCount}.intValue() == 1)]]>
</printWhenExpression>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self">
<reportElement x="200" y="0" width="100" height="18" key="textField" />
<box></box>
<textElement>
<font />
</textElement>
<textFieldExpression class="java.lang.String">
<![CDATA[$F{NAME}]]>
</textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="##0.00" isBlankWhenNull="false" evaluationTime="Group" evaluationGroup="Consecutive" hyperlinkType="None" hyperlinkTarget="Self">
<reportElement x="0" y="0" width="200" height="18" key="textField" />
<box></box>
<textElement>
<font />
</textElement>
<textFieldExpression class="java.lang.String">
<![CDATA[$V{StartRange}+" - " + $F{ID}]]>
</textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="##0.00" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self">
<reportElement x="300" y="0" width="100" height="18" key="textField" />
<box></box>
<textElement>
<font />
</textElement>
<textFieldExpression class="java.math.BigDecimal">
<![CDATA[$V{GroupCount}]]>
</textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="0" isSplitAllowed="true"></band>
</columnFooter>
<pageFooter>
<band height="0" isSplitAllowed="true"></band>
</pageFooter>
<summary>
<band height="0" isSplitAllowed="true"></band>
</summary>
</jasperReport>

Related

Jasper report blank page

My jrxml and java code below . I am trying to create report with some text and values . However blank report is generated . I am pasing map to fill the report as parameter . I have to add 4-5 static lines and then one dynamic variable . I have added these thing in detailed band .whats wrong
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="Untitled_report_2"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="595"
pageHeight="842"
columnWidth="535"
columnSpacing="0"
leftMargin="30"
rightMargin="30"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isTitleNewPage="false"
isSummaryNewPage="false">
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />
<field name="Field" class="java.lang.String"/>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="50" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="50" isSplitAllowed="true" >
</band>
</pageHeader>
<columnHeader>
<band height="30" isSplitAllowed="true" >
</band>
</columnHeader>
<detail>
<band height="100" isSplitAllowed="true" >
<staticText>
<reportElement
x="20"
y="10"
width="180"
height="30"
key="staticText-1"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[4-5 lines text]]></text>
</staticText>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="20"
y="40"
width="60"
height="20"
key="textField-1"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Field}]]></textFieldExpression>
</textField>
<staticText>
<reportElement
x="20"
y="70"
width="160"
height="30"
key="staticText-2"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[4-5 lines text]]></text>
</staticText>
</band>
</detail>
<columnFooter>
<band height="30" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="50" isSplitAllowed="true" >
</band>
</pageFooter>
<lastPageFooter>
<band height="50" isSplitAllowed="true" >
</band>
</lastPageFooter>
<summary>
<band height="50" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>
Java code :
InputStream fileInput = getApplicationContext().getResource("/WEB-INF/reports/myjrxml.jrxml").getInputStream();
JasperReport jasperReport = JasperCompileManager.compileReport(fileInput);
HashMap map = new HashMap();
map.put("Field", "test");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map);
byte[] output1 = JasperExportManager.exportReportToPdf(jasperPrint);
String filename = "d:/test.pdf";
FileOutputStream fo = new FileOutputStream(filename);
fo.write(output1);
fo.close();
You are confusing the report data with parameters. I don't see that you have any report data, which is why you are getting an empty report. Further, you are filling a parameter named "Field" instead of the actual report data. So you either need to create a parameter called "Field" in your report, and then refer to it in the detail band, OR you need to pass the report data into your report something like
JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(dataSet);
jasperPrint = JasperFillManager.fillReport(jasperReport, parameterMap, data);
where dataSet is a collection, such as List<?>. Within the List, you would have an object where one of the properties is Field.
I had also blank page (pdf). Even for the simplest report.Until I sent empty datasource (new JREmptyDataSource())!
This solved my problem:
Map<String, Object> param = new HashMap<>();
param.put("SOME_PARAM","something");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param, new JREmptyDataSource());
Explanation here.
By default, when no datasource info is present in a report, JR generates no pages.

JasperReports: Error creating table trying to use CrossTab without column group

I'm wondering if there is a way to make a table like this using the JapserReports CrossTab or in any other way where the row group is the field value7.
The DataSet used is a JRBeanCollectionDataSource(list of SubViews).
Where SubView is:
public class SubView{
//...
private String value1;
private String value2;
private String value3;
private String value4;
private String value5;
private String value6;
private String value7;
//...getters and setters...
}
Note that there is no need of a column group, but jasper doesn't compile successfully if I don't configure a column group (error message: Crosstab should have at least one column group).
This to me does not seem like a crosstab problem. Crosstab's are used when the columns are dynamic, hence your error message
Crosstab should have at least one column group.
since there is "no need of a column group" the result is achived using the normal detail band and grouping on value7.
So after you put the labels in the columnHeader and the values 1-6 in the detail band you add a grouping on value7 with a groupHeader band
Example (I have only included until value 3 in detail band to sorten the answer
<?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="report2" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="8944f542-2955-4224-933c-5a87fd36f527">
<queryString>
<![CDATA[]]>
</queryString>
<field name="value1" class="java.lang.String"/>
<field name="value2" class="java.lang.String"/>
<field name="value3" class="java.lang.String"/>
<field name="value7" class="java.lang.String"/>
<group name="Value7">
<groupExpression><![CDATA[$F{value7}]]></groupExpression>
<groupHeader>
<band height="21">
<textField>
<reportElement x="0" y="0" width="300" height="20" uuid="208ca6e5-b396-47cb-858b-71039f5bdf7a"/>
<textFieldExpression><![CDATA["Value 7: " + $F{value7}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<background>
<band/>
</background>
<columnHeader>
<band height="50">
<staticText>
<reportElement x="0" y="30" width="100" height="20" uuid="edf0f0f1-c979-4d20-987e-e8decb0b584a"/>
<text><![CDATA[value1]]></text>
</staticText>
<staticText>
<reportElement x="100" y="30" width="100" height="20" uuid="4287323f-e6d3-40d8-a2d4-44981bfa5c59"/>
<text><![CDATA[value2]]></text>
</staticText>
<staticText>
<reportElement x="200" y="30" width="100" height="20" uuid="b9aa7dfd-edd8-439b-b4c7-12916a740da8"/>
<text><![CDATA[value3]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="24">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="2bcc436d-4c3a-4db1-a2ea-87edf92af98f"/>
<textFieldExpression><![CDATA[$F{value1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20" uuid="f893721e-1aa6-44ca-9a9a-ac795ff63a0a"/>
<textFieldExpression><![CDATA[$F{value2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="0" width="100" height="20" uuid="36ad9612-620b-4eec-9608-f26b5306b01a"/>
<textFieldExpression><![CDATA[$F{value3}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
If you like to use crosstab anyway, you need to setup your dataset differently (since also columns become dynamic) check out this for examples: crosstab example

Exporting to Excel with JasperReports: How to add AutoFilter for columns

I am using this code for create report in MS Excel format:
JRXlsExporter exporter = new JRXlsExporter();
From there I don't know if it's possible to tell JasperReports to apply an auto filter on each column.
I was facing the same issue i.e in my spreadsheet(.xls) I wanted to add auto filter to all the columns(15), so I have added one property(Properties expression )name = net.sf.jasperreports.export.xls.auto.filter and value as 'Start' at first column header and same property with value as End at last column header and it worked.
Go to the 'Exporter Parameters' pane and make sure none of the 'Start' or 'Stop' options are set for Auto Filter. Choose the empty space in the related list box (see the attached image). Then run the report again. This time you should see the filters in the right places.
http://community.jaspersoft.com/jaspersoft-studio/issues/6876
JasperReports engine can is able to apply autofilters for columns for MS Excel output format. For applying autofilters we have to use net.sf.jasperreports.export.xls.auto.filter property. We should apply this property for header cells. It is possible to set filter for only one column or for the several columns.
Working example
Datasource
I used the csv datasource in this sample:
language,framework
Java,Guava
Java,Lombok
Java,JasperReports
Java,Spring
Java,Vaadin
C#,ASP.NET MVC
C#,NancyFX
C#,Automapper
JavaScript,AngularJS
JavaScript,React
JavaScript,jQuery
The name of data adapter for this datasource in the example below is frameworks.csv
The report's template
I used Jaspersoft Studio (JSS) for designing a report template.
<?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="excel_filter" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="b521f87a-96ed-43bd-80bd-c7b81ef2e8aa">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="frameworks.csv"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="language" class="java.lang.String"/>
<field name="framework" class="java.lang.String"/>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="278" height="30" uuid="6b8ba60b-3df3-4c78-a780-79ee493ca5f8">
<property name="net.sf.jasperreports.export.xls.auto.filter" value="Start"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Language]]></text>
</staticText>
<staticText>
<reportElement x="278" y="0" width="277" height="30" uuid="731ba580-2168-49f6-b844-d02549d3d83c">
<property name="net.sf.jasperreports.export.xls.auto.filter" value="End"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Framework]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="278" height="30" uuid="7bf9acec-b13a-4261-91c1-0bf6f2c9c784"/>
<textFieldExpression><![CDATA[$F{language}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="278" y="0" width="277" height="30" uuid="d15bd48e-77ee-43df-b11f-4ec1a65811c0"/>
<textFieldExpression><![CDATA[$F{framework}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
I've used the Detail band for showing data. For the first column I set the Start value to the net.sf.jasperreports.export.xls.auto.filter property for staticText in Column Header band (will be the column header in Excel file) and the End value for the second (last) column.
In case using of setting property for only one column the only one filter will be created.
We can easy set property with help of context menu "XLS Tags -> Autofilter -> Start (End)" in JSS.
Output result
The generated output file in MS Excel format contains autofilters for both columns. The file was generated with help of JSS.
Notes:
More information about applying different features for exported Excel files can be found on vendor site

Print an arraylist content with JasperReports

I want to print the content of an ArrayList using JasperReports in Java
Actually I am know little about Jasper Reporting
I use iReport to create Japser Reports and using Java command I will print it.
Now I want to print the student results using JasperReports.
This is my sample results table.
Reg.No SubjectCode Level Semester Grade Marks
132108 CMIS 1113 1 1 A 77
132107 CMIS 1213 1 2 C 57
122101 IMGT 2112 2 1 A 87
122110 IMGT 2213 2 2 A 83
112123 STAT 3113 3 1 C 55
112135 MATH 3213 3 2 B 67
132145 CMIS 1113 1 1 D 17
122118 ELTN 2213 1 2 A 90
112100 CMIS 3213 3 2 A 89
112117 SATA 3113 1 1 A 87
122104 CMIS 2213 2 2 C 54
132104 CMIS 1213 1 2 A 84
So according to my above table I need to print "Results of student in particular level in particular semester".
In my interface I have facility to select the Level and the Semester.
Then the relevant query with generate automatically and results will obtain from the database and using Results object(I create class called 'Results' to store the results of a particular student) I add the results data to a ArrayList.
Now my ArrayList have the Results objects which carries the results of each students in particular level and particular semester.Now I want to print this ArrayList using Jasper report.So expected Jasper Report is like this.For Level 1 and Semester 1,
Reg.No CMIS1113
132108 A
132145 D
For Level 2 and Semester 2,
Reg.No IMGT2213 CMIS2213
122110 A -
122104 - C
Now I have several problems.
1) Normally what I did previously is when I create Jasper Template using iReport I gave the relevant query before creating it.But here query will be changed according to selected Level and Semester.So the result will be changed according to the query.And column headers also changed because subjects are changing.(Number of subject are not similar in each semester and each level)So my question is how can I create a common Jasper Templates to Handle each situation?(if possible)
2) How I print the ArrayList using Java code.I do not know the java code to print the content of ArrayList using Jasper Report.
I know very few things about Jasper Reports.So if you can please help me.Thank You.
you can pass the ArrayList to report as a parameter.
Then in Report create a Subdataset with the same parameter name and type (ArrayList).
Then Create a table component. use the ConnectionExpression:
new net.sf.jasperreports.engine.JREmptyDataSource($P{IN_ARRAY_LIST}.size())
Then map report parameter to table parameter.
Then in TextFields in the table component you can use the expression like that:
$P{IN_ARRAY_LIST}.get($V{REPORT_COUNT})
Make sure that EvaluationTime property of your TextFields is set to now.
UPD:
Short demo report which shows how ArrayList source works:
<?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="ArrayList" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c67d12d3-80cd-46fb-8a79-5c4b0b7c76f9">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="TableDataset" uuid="628eb9fb-e4f0-4f6c-b5b3-277a14fda6e2">
<parameter name="IN_ARRAY_LIST" class="java.util.ArrayList" isForPrompting="false">
<defaultValueExpression><![CDATA[new java.util.ArrayList()]]></defaultValueExpression>
</parameter>
<variable name="ROW_INDEX" class="java.lang.Integer" resetType="None">
<variableExpression><![CDATA[$V{REPORT_COUNT} - 1]]></variableExpression>
</variable>
</subDataset>
<!-- WHEN YOU CALL YOUR REPORT FROM JAVA, YOU SHOULD PUT YOUR ArrayList into IN_ARRAY_LIST PARAM-->
<parameter name="IN_ARRAY_LIST" class="java.util.ArrayList" isForPrompting="false">
<defaultValueExpression><![CDATA[new java.util.ArrayList()]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="555" height="20" uuid="d4548efc-5711-42b3-b08a-cb138c5d55cf">
<!-- THIS IS FOR DEMO ONLY - I PUT 2 ROWS INTO ARRAY LIST USING PrintWhenExpression -->
<printWhenExpression><![CDATA[$P{IN_ARRAY_LIST}.add("ROW_1") && $P{IN_ARRAY_LIST}.add("ROW_2")]]></printWhenExpression>
</reportElement>
<text><![CDATA[Report Title]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="20" splitType="Stretch"/>
</pageHeader>
<pageFooter>
<band height="20" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="50" splitType="Stretch">
<componentElement>
<reportElement key="table" x="0" y="0" width="555" height="50" uuid="042cdee2-a56a-49af-8a1b-740825446ed5"/>
<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="TableDataset" uuid="6f17f8a5-0bcc-4e2a-a900-cdb1e1261d24">
<datasetParameter name="IN_ARRAY_LIST">
<datasetParameterExpression><![CDATA[$P{IN_ARRAY_LIST}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($P{IN_ARRAY_LIST}.size())]]></dataSourceExpression>
</datasetRun>
<jr:column width="555" uuid="236aa389-6073-48fa-9b0f-02dcec80551e">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="555" height="30" uuid="18d3f3cc-13fa-4203-b239-45739b1839dc"/>
<text><![CDATA[ArrayList Field Value]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="555" height="20" uuid="a5bd535e-091b-4eef-a0af-e70fc7d2cce2"/>
<textFieldExpression><![CDATA[$P{IN_ARRAY_LIST}.get($V{ROW_INDEX})]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>
I hope this is clear now.

stretch a row to fit the data in jasper reports using iReport

I use iReport 2.0.5 to generate jrxml file and use the same in my java web propject, I have used all the flags to stretch to fit the data, but it doesn't work
The example:
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement style="dNew" mode="Opaque" x="55" y="0" width="55" height="19" key="value-1" stretchType="RelativeToTallestObject" positionType="Float" isPrintWhenDetailOverflows="true"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{value1}]]></textFieldExpression>
</textField>
It should be able to stretch down based on the band.
If it is a TextField you can set the option "Stretch with Overflow" AFAIK straight StaticTexts will not overflow.
Add the following two properties in your reportElement tag.
name="net.sf.jasperreports.print.keep.full.text" value="true"
name="net.sf.jasperreports.export.xls.wrap.text" value="false"

Categories

Resources