gpt4 book ai didi

jasper-reports - Jasper 报告删除/隐藏空组

转载 作者:行者123 更新时间:2023-12-05 06:42:13 36 4
gpt4 key购买 nike

背景:Jaspersoft studio 6.

有这个交叉表:

enter image description here

交叉表的数据集:

    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 创建了空列。我怎样才能摆脱空列?我尝试过在不同地方为空时为空或在空白时删除行,但没有任何效果。即使在某些时候我可以摆脱空文本,但单元格仍在呈现,因此边框和背景颜色仍然显示。

和源文件(只有一个行组和一个列组的交叉表):

<?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>

最佳答案

好的,问题解决了。与 Jasper 无关(它是一个很好的工具,但老实说它只是缺少一些功能)。解决方案是简单地给 prod3 一个列组和 0 值。关键是任何组字段都没有空值,因此 Jasper 无法生成空组。对于这种情况,只需提供任何现有组成员(mon1 或 mon2)的 prod3 值和 0 值。对于一个真实的案例,必须有一些 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

关于jasper-reports - Jasper 报告删除/隐藏空组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37949758/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com