我在项目中使用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()));
答案 0 :(得分:1)
如果表为空,则不会显示。
campaignSummaryBeanFactory.getCampaignSummaryBeans()
中有任何元素吗?
对于没有数据的情况,在“无数据”范围内添加一些静态文本,如“无数据显示”或甚至表格标题,如果要查看空没有行时的表格。
就代码而言,如果数据源中有1个元素,表也将为空。否则它会使列表中的第一条记录发生变形。请参阅Jasper report missing first row
答案 1 :(得分:0)
你会发现有些人告诉你把表放在摘要带中。但这就是你的桌子没有显示的原因。把它放在一个细节带。