背景:Jaspersoft工作室6。
有这个交叉表:
交叉表的数据集:
select 'prod1' as prod, 'mon1' as month, 1 as val
union all select 'prod1' as prod, 'mon2' as month, 1 as val
union all select 'prod2' as prod, 'mon1' as month, 1 as val
union all select 'prod2' as prod, 'mon2' as month, 1 as val
union all select 'prod3' as prod, null as month, null as val
问题:正如您可能已经注意到的那样,prod3没有与mon1或mon2相关的数据。但我仍然需要在报告中显示它。所以Jasper创建了一个空列。我怎样才能摆脱空列?我在null时尝试了空白,或者在各个地方空白时删除了行,但没有任何效果。即使在某些时候我可以摆脱空文本,但仍然会渲染单元格,所以边框和背景颜色仍然显示。
源文件(只是一个包含一个行组和一个列组的交叉表):
<?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="test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d00fbad1-be1e-4544-b22f-6dca803b6714">
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<queryString>
<![CDATA[select 'prod1' as prod, 'mon1' as month, 1 as val
union all select 'prod1' as prod, 'mon2' as month, 1 as val
union all select 'prod2' as prod, 'mon1' as month, 1 as val
union all select 'prod2' as prod, 'mon2' as month, 1 as val
union all select 'prod3' as prod, null as month, null as val]]>
</queryString>
<field name="prod" class="java.lang.String"/>
<field name="month" class="java.lang.String"/>
<field name="val" class="java.lang.Integer"/>
<summary>
<band height="229" splitType="Stretch">
<crosstab ignoreWidth="true">
<reportElement x="10" y="14" width="520" height="116" isRemoveLineWhenBlank="true" uuid="bb1bb352-1dab-438b-b2c8-b73286af3a9c">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<rowGroup name="prod1" width="60">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{prod}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="d56c7426-8030-4919-8869-86129c230a48"/>
<textFieldExpression><![CDATA[$V{prod1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Crosstab_CT">
<staticText>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="ef3d9aab-f696-48c4-b95b-6be099951c55"/>
<text><![CDATA[Total prod1]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="month1" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{month}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField isBlankWhenNull="false">
<reportElement x="0" y="0" width="60" height="20" uuid="f8dca50f-1f98-425b-bc4e-8a9505901477"/>
<textFieldExpression><![CDATA[$V{month1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CT">
<staticText>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="4960b0b9-4df7-4216-908e-e042ccf2e3a6"/>
<text><![CDATA[Total month1]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="val_MEASURE1" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{val}]]></measureExpression>
</measure>
<crosstabCell width="60" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField isBlankWhenNull="false">
<reportElement x="0" y="0" width="60" height="20" uuid="d207dcd9-1db6-4adb-a7ba-1b539fa06993"/>
<textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="month1">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="59ff8664-202c-4ec7-966c-93c30b372202"/>
<textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="prod1">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="686e7851-9a94-4cbe-aac1-60703fdfc049"/>
<textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="prod1" columnTotalGroup="month1">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="acbe85bf-5cea-40d3-9951-cb0de8baa353"/>
<textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
答案 0 :(得分:0)
好的,解决了这个问题。与Jasper无关(它是一个很好的工具,但说实话它只缺少一些功能)。解决方案只是给prod3一个列组和0值。关键是对任何组字段都没有空值,以便Jasper不能生成空组。对于这种情况,只需给出任何现有组成员(mon1或mon2)和0值的prod3值。对于一个真实的案例,必须有一些sql搞乱来实现这一点,但这比使用jasper的黑客攻击要容易得多。
select 'prod1' as prod, 'mon1' as month, 1 as val
union all select 'prod1' as prod, 'mon2' as month, 1 as val
union all select 'prod2' as prod, 'mon1' as month, 1 as val
union all select 'prod2' as prod, 'mon2' as month, 1 as val
union all select 'prod3' as prod, 'mon1' as month, 0 as val