隐藏列时删除空格 [英] Removing the space when hiding the column

查看:76
本文介绍了隐藏列时删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JasperReports 4.5.0 来生成报告。我正在生成不同格式的报告,如html,csv,pdf,xls,doc。在我的一个报告中,我有6列说 col1,col2,col3,col4,col5,col6 。但根据条件我想隐藏 col4 。为此,我使用 printWhenExpression 。现在它根据条件隐藏了列,但问题是该列占用的空间保持不变。

I am using JasperReports 4.5.0 to generate the reports. I am generating the reports in different formats like html, csv, pdf, xls, doc. In one of my report I have 6 columns say col1, col2, col3, col4, col5, col6. But based on the condition I want to hide the col4. For this I am using the printWhenExpression. Now it is hiding the column based on the condition but the problem is the space occupied by that column is remaining same.

如何删除 col3 col5 之间的空白区域?

How can I remove this empty space in between the col3 and col5?

以下代码用于了解我如何使用它。

The below code is for understanding how i am using it.

<staticText>
                <reportElement x="500" y="0" width="0" height="20" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true">
                    <printWhenExpression><![CDATA[$P{routeType}==Boolean.FALSE]]></printWhenExpression>
                </reportElement>
                <box>
                    <topPen lineWidth="0.25"/>
                    <leftPen lineWidth="0.25"/>
                    <bottomPen lineWidth="0.25"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Col4]]></text>
            </staticText>

<textField isBlankWhenNull="true">
                <reportElement x="500" y="0" width="0" height="20" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true">
                    <printWhenExpression><![CDATA[$P{routeType}==Boolean.FALSE]]></printWhenExpression>
                </reportElement>
                <box>
                    <leftPen lineWidth="0.25"/>
                    <bottomPen lineWidth="0.25"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{col4}]]></textFieldExpression>
            </textField>

仅当routeType值为false时,才会打印此字段。否则,应删除空格为空的列还有。

This field will print only if the routeType value is false.Otherwise it should remove the column with empty space also.

推荐答案


  • 您可以使用 JasperReports API DynamicJasper API

  • 这是使用 DynamicJasper API 的样本

    Here is the samples of using DynamicJasper API


    • 您可以使用假字段( textField )显示一列的数据,而不是显示两个字段(两个字段)列)

    • You can use "fake" field (textField) for showing data of one column instead of showing two fields (two columns)

    你可以放另一个 textField (宽度为两个 textFields )在 textFields 下。使用 printWhenExpression 属性,您可以显示两列或一列。

    You can put another textField (which has the width of two textFields) under the both textFields. Using printWhenExpression property you can show two columns or one.

    这是我的报告设计(在 iReport 中):

    Here is my report's design (in iReport):

    我的 jrxml 文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <jasperReport ..>
        <parameter name="hideStreetColumn" class="java.lang.Boolean">
            <defaultValueExpression><![CDATA[false]]></defaultValueExpression>
        </parameter>
        <queryString>
            <![CDATA[SELECT id, street, city FROM address]]>
        </queryString>
        <field name="ID" class="java.lang.Integer"/>
        <field name="STREET" class="java.lang.String"/>
        <field name="CITY" class="java.lang.String"/>
        <title>
            <band height="79" splitType="Stretch">
                <staticText>
                    <reportElement x="139" y="13" width="279" height="20"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Sample of hiding column]]></text>
                </staticText>
                <textField>
                    <reportElement x="189" y="33" width="211" height="20"/>
                    <box leftPadding="10"/>
                    <textElement/>
                    <textFieldExpression><![CDATA["To hide Street column: " + $P{hideStreetColumn}]]></textFieldExpression>
                </textField>
            </band>
        </title>
        <detail>
            <band height="20" splitType="Stretch">
                <textField>
                    <reportElement x="100" y="0" width="200" height="20">
                        <printWhenExpression><![CDATA[$P{hideStreetColumn}]]></printWhenExpression>
                    </reportElement>
                    <box leftPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="0" y="0" width="100" height="20"/>
                    <box leftPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="100" y="0" width="100" height="20">
                        <printWhenExpression><![CDATA[!$P{hideStreetColumn}]]></printWhenExpression>
                    </reportElement>
                    <box leftPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{STREET}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="200" y="0" width="100" height="20">
                        <printWhenExpression><![CDATA[!$P{hideStreetColumn}]]></printWhenExpression>
                    </reportElement>
                    <box leftPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
    </jasperReport>
    

    要显示所有三列,我们应设置 hideStreetColumn 参数 false 。结果将是:

    To show all three columns we should set hideStreetColumn parameter to false. The result will be:

    要仅显示两列(街道列隐藏),我们应将 hideStreetColumn 参数设置为即可。结果将是:

    To show only two columns (the Street column is hiding) we should set hideStreetColumn parameter to true. The result will be:

    这篇关于隐藏列时删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆