【问题标题】:How do I show an empty table in iReport 3.0.0?如何在 iReport 3.0.0 中显示一个空表?
【发布时间】:2013-10-08 23:37:40
【问题描述】:

我正在修改一个现有的 iReport 文件,据说该文件要求来自程序的输入。然后将输入放在一个表中,我假设它会在数据进入时自动添加行。

但是,该程序不会输出数据,并且不再需要这样做。所以现在我只需要显示一个空表。

我在 iReport 中所做的是删除所有参数痕迹(因为不再需要它们,然后复制并粘贴所有单元格,直到它们到达页面底部。现在没有任何单元格(除了标题和顶行,因为它们有静态文本)是可见的,其中一份报告甚至显示了一个空白页。

我尝试将报告属性:无数据时:设置为无数据部分或所有部分 - 无详细信息,但它仍然是空的,没有可见的单元格。我还尝试在文本字段中放置一个空格,希望它会显示,甚至用矩形替换它们(这在另一个报告中有效)。但是,没有任何效果。报告仍然只显示标题。

我该如何解决这个问题?谢谢。

这是 JRXML:

<?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="ApprenticeEmployment1"
         columnCount="1"
         printOrder="Vertical"
         orientation="Landscape"
         pageWidth="1008"
         pageHeight="612"
         columnWidth="948"
         columnSpacing="0"
         leftMargin="30"
         rightMargin="30"
         topMargin="20"
         bottomMargin="20"
         whenNoDataType="AllSectionsNoDetail"
         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.*" />

    <parameter name="imagedir" isForPrompting="false" class="java.lang.String"/>

    <field name="REGION" class="java.lang.String"/>
    <field name="PROVINCE" class="java.lang.String"/>
    <field name="FULL_QUALIFICATION" class="java.lang.String"/>
    <field name="DELIVERY" class="java.lang.String"/>
    <field name="SECTOR" class="java.lang.String"/>
    <field name="STUDENT_ID" class="java.lang.String"/>
    <field name="LAST_NAME" class="java.lang.String"/>
    <field name="FIRST_NAME" class="java.lang.String"/>
    <field name="MI" class="java.lang.String"/>
    <field name="CONTACT_NUMBER" class="java.lang.String"/>
    <field name="E_MAIL" class="java.lang.String"/>
    <field name="STREET" class="java.lang.String"/>
    <field name="BARANGAY" class="java.lang.String"/>
    <field name="CITY" class="java.lang.String"/>
    <field name="SEX" class="java.lang.String"/>
    <field name="DOB" class="java.lang.String"/>
    <field name="AGE" class="java.math.BigDecimal"/>
    <field name="CIVIL_STAT" class="java.lang.String"/>
    <field name="EDUC_LEVEL" class="java.lang.String"/>
    <field name="DATE_STARTED" class="java.lang.String"/>
    <field name="DATE_FINISHED" class="java.lang.String"/>
    <field name="REMARKS" class="java.lang.String"/>

        <background>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </background>
        <title>
            <band height="51"  isSplitAllowed="true" >
                <staticText>
                    <reportElement
                        x="0"
                        y="30"
                        width="948"
                        height="21"
                        key="staticText-1"/>
                    <box></box>
                    <textElement textAlignment="Center" verticalAlignment="Bottom">
                        <font pdfFontName="Helvetica-Bold" isBold="true"/>
                    </textElement>
                <text><![CDATA[Apprentice Report Form]]></text>
                </staticText>
                <image  hAlign="Center" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                    <reportElement
                        x="238"
                        y="0"
                        width="470"
                        height="37"
                        key="image-1"/>
                    <box></box>
                    <graphicElement stretchType="NoStretch"/>
                    <imageExpression class="java.lang.String"><![CDATA[$P{imagedir}+"goldilocks-small.JPG"]]></imageExpression>
                </image>
            </band>
        </title>
        <pageHeader>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </pageHeader>
        <columnHeader>
            <band height="65"  isSplitAllowed="true" >
                <staticText>
                    <reportElement
                        x="0"
                        y="18"
                        width="34"
                        height="31"
                        key="staticText-3"/>
                    <box>                   <topPen lineWidth="0.25"/>
                    <leftPen lineWidth="0.25"/>
                    <bottomPen lineWidth="0.25"/>
                    <rightPen lineWidth="0.25"/>
</box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font/>
                    </textElement>
                <text><![CDATA[Sex]]></text>
                </staticText>
                <staticText>
                    <reportElement
                        x="271"
                        y="18"
                        width="58"
                        height="31"
                        key="staticText-4"/>
                    <box>                   <topPen lineWidth="0.25"/>
                    <leftPen lineWidth="0.25"/>
                    <bottomPen lineWidth="0.25"/>
                    <rightPen lineWidth="0.25"/>
</box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font/>
                    </textElement>
                <text><![CDATA[Scholarship]]></text>
                </staticText>
                <staticText>
                    <reportElement
                        x="453"
                        y="18"
                        width="42"
                        height="31"
                        key="staticText-5"/>
                    <box>                   <topPen lineWidth="0.25"/>
                    <leftPen lineWidth="0.25"/>
                    <bottomPen lineWidth="0.25"/>
                    <rightPen lineWidth="0.25"/>
</box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font/>
                    </textElement>
                <text><![CDATA[Client Type
]]></text>
                </staticText>
                <staticText>
                    <reportElement
                        x="0"
                        y="1"
                        width="741"
                        height="17"
                        key="staticText-6"/>
            </band>
        </columnHeader>
        <detail>
            <band height="456"  isSplitAllowed="true" >
                <textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                    <reportElement
                        x="0"
                        y="432"
                        width="34"
                        height="18"
                        key="textField-378"
                        stretchType="RelativeToTallestObject"
                        positionType="Float"/>
                    <textElement verticalAlignment="Middle">
                        <font size="8"/>
                    </textElement>
                <textFieldExpression   class="java.lang.String"><![CDATA[]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                    <reportElement
                        x="0"
                        y="72"
                        width="34"
                        height="18"
                        key="textField-458"
                        stretchType="RelativeToTallestObject"
                        positionType="Float"/>
                    <textElement verticalAlignment="Middle">
                        <font size="8"/>
                    </textElement>
                <textFieldExpression   class="java.lang.String"><![CDATA[]]></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>

我确实编辑了很多“框”,所以如果格式错误,那是我的问题,而不是 JRXML 本身。

问候, 扎克猎鹰

【问题讨论】:

  • 你能发布 JRXML 吗?
  • 是的,抱歉我没有第一次发布。

标签: jasper-reports ireport


【解决方案1】:

创建一个有N条空记录的表,即使你没有数据。

  1. 创建对象表
  2. 将您的 DataSEt 附加到此表或使用空数据源
  3. 在“报告检查器”中选择您的表格并单击右键
  4. 选择:“编辑表数据源”
  5. 在你写的窗口中:new net.sf.jasperreports.engine.JREmptyDataSource(44)
  6. 运行您的报告

44是显示空记录的数字。

【讨论】:

    【解决方案2】:

    在表格属性中,在表格部分下选择“所有部分,无详细信息”

    【讨论】:

      【解决方案3】:

      你可以试试这个条件

      $P{Parameter}==null ? "All" : $P{Parameter}
      

      如果您不选择任何输入值,此条件将为您提供所有文本。

      【讨论】:

      • 我应该把它放在哪里,在文本字段中?谢谢你的回答,顺便说一句。
      • 无论您在何处显示参数值(文本文件)。
      • 我把它放在文本字段中,修改为 $F{PARAM_EXAMPLE}==null ? “全部”:$F{PARAM_EXAMPLE}。不幸的是,它没有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-29
      • 2014-05-10
      相关资源
      最近更新 更多