Removing Blank Entries from a Jasper Report

I created a report in jrxml. I indicated only to print the details of each value if one of my fields is populated using the <printWhenExpression> with a value similar to this:

 <textField> <reportElement x="670" y="4" width="105" height="20" isRemoveLineWhenBlank="true"> <printWhenExpression><![CDATA[$F{name}!= null]]></printWhenExpression> </reportElement> <textElement> <font fontName="Arial" size="10"/> </textElement> <textFieldExpression><![CDATA[$F{value2}]]></textFieldExpression> 

This works when filtering only relevant data, however it leaves me with a lot of blank lines in the report. I included the condition isRemoveLineWhenBlank="true" to remove these empty lines from my report. This took my report from 12 pages to 5, however I still observe a large number of blank lines in the report.

Here is a screenshot of my reporting project at Irire.

enter image description here

And here is a screenshot from the report (I closed the name of my company from the classes)

enter image description here

Full JRXML 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="RIOBridgeReport" pageWidth="1530" pageHeight="842" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="10" rightMargin="5" topMargin="10" bottomMargin="10"> <property name="ireport.zoom" value="2.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="columnHeader"/> <parameter name="title" class="java.lang.String"/> <parameter name="oneliner" class="java.lang.String"/> <field name="name" class="java.lang.String"> <fieldDescription><![CDATA[id[starts-with(.,'USCS')]]]></fieldDescription> </field> <field name="class" class="java.lang.String"> <fieldDescription><![CDATA[class]]></fieldDescription> </field> <field name="value" class="java.lang.String"> <fieldDescription><![CDATA[constructor-arg/value]]></fieldDescription> </field> <field name="value1" class="java.lang.String"> <fieldDescription><![CDATA[constructor-arg[1]/value]]></fieldDescription> </field> <field name="value2" class="java.lang.String"> <fieldDescription><![CDATA[constructor-arg[2]/value]]></fieldDescription> </field> <variable name="runDate" class="java.lang.String"> <initialValueExpression><![CDATA[new java.text.SimpleDateFormat("dd-MMM-yyyy HH:mm:ss Z").format(new java.util.Date())]]></initialValueExpression> </variable> <background> <band splitType="Stretch"/> </background> <title> <band height="53" splitType="Stretch"> <textField isBlankWhenNull="true"> <reportElement x="12" y="12" width="496" height="20"/> <textElement textAlignment="Center"> <font fontName="Arial" size="14" isBold="true"/> </textElement> <textFieldExpression><![CDATA[$P{title} + " - " + $V{runDate}]]></textFieldExpression> </textField> <image> <reportElement x="616" y="0" width="84" height="53"/> <imageExpression><![CDATA["citi_corp_logo.gif"]]></imageExpression> </image> <textField isBlankWhenNull="true"> <reportElement x="12" y="32" width="496" height="20"/> <textElement textAlignment="Center"> <font fontName="Arial" size="10" isBold="true"/> </textElement> <textFieldExpression><![CDATA[$P{oneliner}]]></textFieldExpression> </textField> </band> </title> <columnHeader> <band height="23" splitType="Stretch"> <staticText> <reportElement x="12" y="2" width="85" height="20"/> <textElement> <font fontName="Arial" size="10" isBold="true" isUnderline="false"/> </textElement> <text><![CDATA[Bean Name]]></text> </staticText> <staticText> <reportElement x="228" y="2" width="85" height="20"/> <textElement> <font fontName="Arial" size="10" isBold="true" isUnderline="false"/> </textElement> <text><![CDATA[Class]]></text> </staticText> <staticText> <reportElement x="428" y="2" width="105" height="20"/> <textElement> <font fontName="Arial" size="10" isBold="true" isUnderline="false"/> </textElement> <text><![CDATA[Value]]></text> </staticText> <staticText> <reportElement x="543" y="2" width="105" height="20"/> <textElement> <font fontName="Arial" size="10" isBold="true" isUnderline="false"/> </textElement> <text><![CDATA[Value1]]></text> </staticText> <staticText> <reportElement x="670" y="2" width="105" height="20"/> <textElement> <font fontName="Arial" size="10" isBold="true" isUnderline="false"/> </textElement> <text><![CDATA[Value2]]></text> </staticText> </band> </columnHeader> <detail> <band height="24"> <textField isBlankWhenNull="true"> <reportElement x="12" y="2" width="216" height="20" isRemoveLineWhenBlank="true"> <printWhenExpression><![CDATA[$F{name}!= null]]></printWhenExpression> </reportElement> <textElement> <font fontName="Arial" size="10"/> </textElement> <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> </textField> <textField> <reportElement x="228" y="2" width="185" height="20"> <printWhenExpression><![CDATA[$F{name}!= null]]></printWhenExpression> </reportElement> <textElement> <font fontName="Arial" size="10"/> </textElement> <textFieldExpression><![CDATA[$F{class}]]></textFieldExpression> </textField> <textField> <reportElement x="428" y="2" width="105" height="20"> <printWhenExpression><![CDATA[$F{name}!= null]]></printWhenExpression> </reportElement> <textElement> <font fontName="Arial" size="10"/> </textElement> <textFieldExpression><![CDATA[$F{value}]]></textFieldExpression> </textField> <textField> <reportElement x="543" y="4" width="105" height="20"> <printWhenExpression><![CDATA[$F{name}!= null]]></printWhenExpression> </reportElement> <textElement> <font fontName="Arial" size="10"/> </textElement> <textFieldExpression><![CDATA[$F{value1}]]></textFieldExpression> </textField> <textField> <reportElement x="670" y="4" width="105" height="20"> <printWhenExpression><![CDATA[$F{name}!= null]]></printWhenExpression> </reportElement> <textElement> <font fontName="Arial" size="10"/> </textElement> <textFieldExpression><![CDATA[$F{value2}]]></textFieldExpression> </textField> </band> </detail> <noData> <band height="20"> <staticText> <reportElement x="146" y="0" width="200" height="20"/> <textElement textAlignment="Center"> <font fontName="Arial" size="14" isBold="true"/> </textElement> <text><![CDATA[No data found]]></text> </staticText> </band> </noData> </jasperReport> 

As you can see, the report has a large number of gaps. Is there a way to completely delete them or click blank lines at the end of the report.

+4
source share
2 answers

Try to place everything inside the frame and add the line "Delete line when it is empty" to the frame.

+4
source

Instead of isRemoveLineWhenBlank, the field uses the details bar properties. Therefore, this condition must be specified in the printWhenExpression data strip properties. .

+1
source

Source: https://habr.com/ru/post/1481405/


All Articles