简体   繁体   中英

iReport (JasperReports) extra row issue

I am getting an extra empty row between data when I am importing it from the database and formatting the report in Excel sheet.

EDIT (clarification from a comment): The output in Excel shows an extra blank row between records and and extra blank column between fields.

  • Add net.sf.jasperreports.export.xls.remove.empty.space.between.columns and net.sf.jasperreports.export.xls.remove.empty.space.between.rows properties to report template.

net.sf.jasperreports.export.xls.remove.empty.space.between.columns - Specifies whether the empty spacer columns should be removed or not.

net.sf.jasperreports.export.xls.remove.empty.space.between.rows - Specifies whether the empty spacer rows should be removed or not.

The sample:

<jasperReport ...>
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
    <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>

The information about configuration properties is here .

  • You can set isRemoveLineWhenBlank and isBlankWhenNull for textField element for hiding blank row.

The sample how to remove the whole line if the current textField is empty:

<textField isBlankWhenNull="true">
    <reportElement x="0" y="0" width="100" height="20" isRemoveLineWhenBlank="true"/>
    <textElement/>
    <textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
  • Another assumption is to change the height of all textField (or/and staticText ) elements in the Band .

In case this design:

在 textField 和乐队的边界之间有一个空间的设计

you will have a space between any two rows.

In case this design ( textField height is equal to the Band's height):文本字段高度等于乐队的高度

the each line will be exactly under the other.

Every thing that Alex K states in his Dec 2 '11 answer is correct. But a few other settings may be helpful. These settings help when the text of the report stretches the detail band.

On every field in the detail band set:

positionType="Float"

stretchType="RelativeToTallestObject"

Example:

<detail>
    <band height="20" splitType="Prevent">
        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
            <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Transparent" x="372" y="0" width="100" height="20"/>
            <textElement/>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{your column name}]]></textFieldExpression>
        </textField>

This will force the all fields to be one height. The float setting tells the field to minimize the distance between the previous and next row. The RelativeToTallestObject setting tells all fields in the band to be the same height as the tallest field. These two settings help eliminate 'empty space' which shows up as unwanted cells in Excel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM