How to merge cells in same column, apply rowspan?

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 … Read more

doing comparison if else in JasperReports

iReport (JasperReports) uses a Ternary operator. For example, consider the following logic: IF boolean condition THEN execute true code ELSE execute false code END IF Using a ternary operator, this becomes: boolean condition ? execute true code : execute false code When using a variable with the following expression: $F{column_value}.intValue() == 42 ? “Life, Universe, … Read more

How to remove extra space between textfield in JasperReports?

You can use 3 textField elements with isRemoveLineWhenBlank property set to true value. The sample (jrxml file): <?xml version=”1.0″ encoding=”UTF-8″?> <jasperReport .. topMargin=”0″ bottomMargin=”0″> <parameter name=”parameter1″ class=”java.lang.String”> <defaultValueExpression><![CDATA[null]]></defaultValueExpression> </parameter> <parameter name=”parameter2″ class=”java.lang.String”> <defaultValueExpression><![CDATA[null]]></defaultValueExpression> </parameter> <parameter name=”parameter3″ class=”java.lang.String”> <defaultValueExpression><![CDATA[null]]></defaultValueExpression> </parameter> <title> <band height=”102″ splitType=”Stretch”> <textField isBlankWhenNull=”true”> <reportElement x=”163″ y=”9″ width=”100″ height=”20″ isRemoveLineWhenBlank=”true”/> <box> <topPen lineWidth=”1.0″/> <leftPen … Read more

Adding table border in jasperreports

You can add borders with help of GUI designer (iReport, for example) or you can add the box element manually (edit the jrxml file) like in this sample: <textField> <reportElement x=”29″ y=”17″ width=”100″ height=”20″/> <box> <topPen lineWidth=”1.0″/> <leftPen lineWidth=”1.0″/> <bottomPen lineWidth=”1.0″/> <rightPen lineWidth=”1.0″/> </box> <textElement/> <textFieldExpression><![CDATA[$F{field}]]></textFieldExpression> </textField> In iReport you can use “Padding And Borders” … Read more

Jasper Reports Show “Page X of Y” using a single text field

Jaspersoft Studio, 6+ For Jaspersoft Studio v6, or if the first page number is duplicated, try this solution, which uses $V{MASTER_CURRENT_PAGE} and $V{MASTER_TOTAL_PAGE} with an evaluation time of Master. Jaspersoft Studio For other versions of Jaspersoft Studio, try the steps outlined in the subsequent subsections. Create Variable Create a variable as follows: Create a variable … Read more

How to pass main report data source to subreport (JasperReports)?

You can pass datasource via the built-in REPORT_DATA_SOURCE parameter. The example: <subreport> <reportElement x=”261″ y=”25″ width=”200″ height=”100″/> <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + “subreport.jasper”]]></subreportExpression> </subreport> You can create new instance of datasource based on variable, parameter or field. The sample: <variable name=”HeadingsCollection” class=”java.util.Collection” calculation=”System”> <initialValueExpression><![CDATA[new java.util.ArrayList()]]></initialValueExpression> </variable> … <subreport> <reportElement x=”0″ y=”0″ width=”515″ height=”20″/> <subreportParameter name=”ReportTitle”> <subreportParameterExpression><![CDATA[$P{ReportTitle}]]></subreportParameterExpression> </subreportParameter> … Read more

Group several same value field into a single cell

You can use 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=”year_sum_quarter” 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[]]> </queryString> <field name=”year” class=”java.lang.Integer”/> <field name=”month” class=”java.lang.String”/> <field name=”sum” class=”java.lang.Integer”/> <field name=”q” class=”java.lang.Integer”/> <variable name=”yearSum” class=”java.lang.Integer” resetType=”Group” resetGroup=”yearGroup” calculation=”Sum”> <variableExpression><![CDATA[$F{sum}]]></variableExpression> </variable> <variable … Read more