2

我在我的项目中使用 JasperReports,在摘要带中使用表格组件并提供数据,JRBeanCollectionDataSource但在提取报告后,仅获取报告的标题并且未显示表格。

这是我的 .jrxml

<?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="CampaignSummary" language="groovy" pageWidth="1400" pageHeight="1000" orientation="Landscape" columnWidth="1360" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ef078799-c539-490f-b244-d493f4522ef2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="163"/>
<property name="ireport.y" value="0"/>
<style name="table">
    <box>
        <pen lineWidth="1.0" lineColor="#000000"/>
    </box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#00FFFF"/>
<style name="table_CH" mode="Opaque" backcolor="#BFFFFF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
    </box>
    <conditionalStyle>
        <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
        <style backcolor="#EFFFFF"/>
    </conditionalStyle>
</style>
<subDataset name="TableDataset" uuid="c99fd89d-9d8f-488f-95db-360a7f5aba96">
    <field name="CampaignID" class="java.lang.String">
        <fieldDescription><![CDATA[me.CampaignID]]></fieldDescription>
    </field>
    <field name="CampaignName" class="java.lang.String">
        <fieldDescription><![CDATA[Campaign Name]]></fieldDescription>
    </field>
    .
            .
            .
    ......some more fields....
            .
            .
    <field name="NetImpact" class="java.lang.String">
        <fieldDescription><![CDATA[Net Impact]]></fieldDescription>
    </field>
</subDataset>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="54" splitType="Stretch">
        <staticText>
            <reportElement uuid="8b41287b-3930-416a-ba00-7f4a9c907e26" x="0" y="0" width="1360" height="54"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font fontName="Arial Rounded MT Bold" size="24"/>
            </textElement>
            <text><![CDATA[Campaign Summary Report]]></text>
        </staticText>
    </band>
</title>
<summary>
    <band height="239" splitType="Stretch">
        <frame>
            <reportElement uuid="61313d06-6df1-4212-ab8f-8e311dc5ad33" x="0" y="0" width="1360" height="87"/>
        </frame>
        <frame>
            <reportElement uuid="c04b08f6-89d3-4104-87ba-adecd3c4f7dd" x="0" y="87" width="1360" height="152"/>
            <componentElement>
                <reportElement uuid="8afc21c1-7b57-4dab-8178-8810c1183dd9" key="table" style="table" x="0" y="0" width="1360" height="152"/>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="TableDataset">
                        <dataSourceExpression>
                            <![CDATA[($P{REPORT_DATA_SOURCE})]]>
                        </dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90" uuid="eece2ecf-027d-4ef1-bd05-8d7d6bbbc0b0">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="c0d108a0-9f4b-4ec3-b9d0-664ea0724584" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Campaign Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="6a8f7bf6-5e9b-4f77-a524-9a8d7f0ee2ca" x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[String.valueOf($F{CampaignName})]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    .
                                            .
                                            .some more columns...
                                            .
                    <jr:column width="80" uuid="312f9143-cee8-46fb-a296-27172c4fca98">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="22ec2935-d4a9-4b64-856d-e64d72f0d856" x="0" y="0" width="80" height="30"/>
                                <textElement/>
                                <text><![CDATA[Net Impact]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="071cddad-63f1-47bc-8da5-a2d6752e3abe" x="0" y="0" width="80" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[String.valueOf($F{NetImpact})]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </frame>
    </band>
</summary>

和java代码是

CampaignSummaryBeanFactory campaignSummaryBeanFactory =new CampaignSummaryBeanFactory();
JasperFillManager.fillReportToFile("build/reports/CampaignSummary.jasper", null, new JRBeanCollectionDataSource(campaignSummaryBeanFactory.getCampaignSummaryBeans()));
4

2 回答 2

1

如果表格为空,则不会显示表格。

你有什么元素campaignSummaryBeanFactory.getCampaignSummaryBeans()吗?

  1. 对于没有数据的情况,如果您想在没有行的情况下查看空表,请在“无数据”区域中添加一些静态文本,例如“没有要显示的数据”,甚至是表的标题.

  2. 就您的代码而言,如果数据源中有 1 个元素,该表也将为空。否则它将保留列表中的第一条记录。查看Jasper 报告缺少第一行

于 2014-12-30T12:10:21.650 回答
0

您会发现有些人告诉您将表格放在摘要带中。但这就是您的表格未显示的原因。把它放在一个细节带中。

于 2014-02-21T07:04:28.980 回答