嗨,我是贾斯珀报告的新手。我正在使用jasper报告将数据导出为PDF格式,它工作正常。但问题是我希望列是动态的,即根据用户输入选择,报告列可能会有所不同(用户被选中一个仅限旅行列,如果他选择了两次旅行,两列将会出现这样的情况)。 一个输入意味着表格如下所示
Date Trip1
11/04/15 5
12/04/15 8
13/04/15 9
两个输入均值表如下所示
Date Trip1 Trip2
11/04/15 5 56
12/04/15 8 34
13/04/15 9 22
所以任何人都帮助他如何做这件事。 这是我的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="all_dto" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="89b85722-ba33-45f9-8706-74b3dacad933">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="title" class="java.lang.String">
<defaultValueExpression><![CDATA[DDDDD]]></defaultValueExpression>
</parameter>
<parameter name="reportId" class="java.lang.String"/>
<parameter name="operationTime" class="java.lang.String"/>
<field name="Date" class="java.lang.String"/>
<field name="Distance" class="java.lang.String"/>
<variable name="agencyName" class="java.lang.String"/>
<background>
<band/>
</background>
<title>
<band height="30">
<frame>
<reportElement uuid="85d468b6-12c0-4042-8566-b50602873de0" mode="Opaque" x="0" y="0" width="500" height="24" backcolor="#006699"/>
<textField>
<reportElement uuid="5769f1cf-6378-4bb0-b172-4716e2eb79fd" x="18" y="0" width="450" height="18" forecolor="#FFFFFF"/>
<textElement markup="none">
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{title}]]></textFieldExpression>
</textField>
</frame>
</band>
</title>
<columnHeader>
<band height="21">
<staticText>
<reportElement uuid="6fe065c4-169e-4505-b362-ac4251c8b1f6" mode="Opaque" x="0" y="0" width="100" height="21" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement>
<font size="9" isBold="true"/>
</textElement>
<text><![CDATA[Date]]></text>
</staticText>
<staticText>
<reportElement uuid="6fe065c4-169e-4505-b362-ac4251c8b1f6" mode="Opaque" x="100" y="1" width="83" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement>
<font size="9" isBold="true"/>
</textElement>
<text><![CDATA[Distance]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="21">
<textField>
<reportElement uuid="8d449f27-3ff5-4f72-9da6-c0f816e48c9e" x="0" y="0" width="100" height="21" forecolor="#666666"/>
<textElement>
<font size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{Date}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="8d449f27-3ff5-4f72-9da6-c0f816e48c9e" x="100" y="1" width="83" height="20" forecolor="#666666"/>
<textElement>
<font size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{Distance}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band height="30">
<textField>
<reportElement uuid="df503057-dcfe-47a4-ba3c-240611bdf374" mode="Opaque" x="0" y="17" width="515" height="13" backcolor="#E6E6E6"/>
<textElement textAlignment="Right">
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement uuid="361f0bb0-014d-402f-80f3-fe748ced00a9" mode="Opaque" x="515" y="17" width="40" height="13" backcolor="#E6E6E6"/>
<textElement>
<font size="6"/>
</textElement>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement uuid="98d5cae2-2532-4834-8de0-73b47852ac1f" x="0" y="17" width="100" height="13"/>
<textElement/>
<textFieldExpression><![CDATA[$P{operationTime}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
</jasperReport>
答案 0 :(得分:0)
您可以通过至少两种不同的方式完成此操作。使用交叉表(尽管这很明显,请参阅Jasper帮助)或创建多个列。
在报告属性中,选择列数作为您想要显示的最大值。然后创建一个组并中断要分组的数据(在本例中为trip)。创建列页眉和页脚,并将行程字段放在标题中。在详细信息字段中,从调色板中添加一个分栏符。
请注意,您需要传入一个包含要显示的行程的集合参数,并与查询中的$ X IN运算符匹配。
请参阅下面的代码,该代码将与sqlserver数据源一起使用:
<?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="report12" language="groovy" columnCount="3" pageWidth="595" pageHeight="842" columnWidth="185" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="427aadaf-d91a-41be-8ab6-4c8b67934889">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select getdate() date,
1 as trip_no,
11 as val
union
select getdate() date,
2 as trip_no,
12 as val
union
select getdate() date,
3 as trip_no,
15 as val
union
select getdate() date,
1 as trip_no,
25 as val
union
select getdate() date,
2 as trip_no,
10 as val
union
select getdate() date,
3 as trip_no,
5 as val
]]>
</queryString>
<field name="date" class="java.sql.Timestamp"/>
<field name="trip_no" class="java.lang.Integer"/>
<field name="val" class="java.lang.Integer"/>
<group name="x">
<groupExpression><![CDATA[$F{trip_no}]]></groupExpression>
</group>
<group name="trip">
<groupExpression><![CDATA[$F{trip_no}]]></groupExpression>
<groupHeader>
<band height="20">
<textField>
<reportElement uuid="531f49e8-78a7-4786-a788-7e7588263e48" x="0" y="0" width="183" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{trip_no}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
<groupFooter>
<band height="1">
<break type="Column">
<reportElement uuid="a224f69e-5d76-4cd2-8959-373bdaa51b78" x="0" y="0" width="100" height="1"/>
</break>
</band>
</groupFooter>
</group>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="8f94c9e6-e5bf-4904-a529-923acca4dc2a" x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="9997bf64-2fe8-47fd-9b76-b501d210d309" x="100" y="0" width="83" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{val}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>