我想知道是否有一种方法可以在总计列之后为我提供交叉表的自定义列。
我需要打印dinamic列及其总数,并在末尾添加一些信息,但是找不到在总列之后添加自定义信息的方法...
有人尝试做类似的事情吗?
答案 0 :(得分:0)
您可以通过添加具有常量表达式的顶级列组,将组标题高度设置为0并使用组总数列显示其他值来实现。可以使用calculation="Nothing"
或其他方式(取决于具体情况)将这些值作为度量传递。
这是执行我建议的报告。这是经过修改的JasperReports示例报告,您可以在Jaspersoft Studio中与示例数据库一起运行它。
<?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="ProductsReport" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="782" leftMargin="30" rightMargin="30" topMargin="30" bottomMargin="30" whenNoDataType="AllSectionsNoDetail" uuid="d8258224-60b6-4c49-b0e9-a411ee2fbd39">
<style name="Sans_Normal" isDefault="true" fontName="DejaVu Sans" fontSize="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="Sans_Bold" fontName="DejaVu Sans" fontSize="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
<style name="cell">
<box>
<pen lineWidth="0.5"/>
</box>
</style>
<subDataset name="Customer_Quantity" uuid="d7fa233d-253a-4620-93b5-d8c430099436">
<parameter name="CityParam" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT product.name, positions.quantity,
address.firstname, address.lastname, address.street
FROM product, positions, address, document
WHERE product.id = positions.productid AND
address.id = document.addressid AND
document.id = positions.documentid AND
address.city=$P{CityParam}]]>
</queryString>
<field name="Name" class="java.lang.String"/>
<field name="Quantity" class="java.lang.Integer"/>
<field name="FirstName" class="java.lang.String"/>
<field name="LastName" class="java.lang.String"/>
<field name="street" class="java.lang.String"/>
</subDataset>
<title>
<band height="70">
<crosstab isRepeatColumnHeaders="false">
<reportElement x="0" y="0" width="782" height="70" uuid="d3aca7c7-1165-4cb5-a7ca-e67b01a5b15d"/>
<crosstabDataset>
<dataset>
<datasetRun subDataset="Customer_Quantity" uuid="69151f6b-5c48-4d23-b978-e8fdfbf7b631">
<datasetParameter name="CityParam">
<datasetParameterExpression><![CDATA["Seattle"]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
</dataset>
</crosstabDataset>
<rowGroup name="NameGroup" width="80" totalPosition="None">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{FirstName} + " " + $F{LastName}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents style="cell">
<textField>
<reportElement style="Sans_Bold" x="5" y="0" width="75" height="10" uuid="7f161b84-95ad-4ce4-b619-dfdabb44899e"/>
<textFieldExpression><![CDATA[$V{NameGroup}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
</rowGroup>
<columnGroup height="0" name="dummy" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[""]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents style="cell">
<staticText>
<reportElement style="Sans_Bold" x="0" y="0" width="80" height="50"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Street]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<columnGroup name="ProductGroup" height="50" totalPosition="End" headerPosition="Stretch">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{Name}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents style="cell">
<textField>
<reportElement style="Sans_Bold" x="0" y="0" width="20" height="50" uuid="2af151be-c117-41c0-864d-279ef72186ec"/>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="Left"/>
<textFieldExpression><![CDATA[$V{ProductGroup}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents backcolor="#FFFF60" mode="Opaque" style="cell">
<staticText>
<reportElement style="Sans_Bold" x="0" y="0" width="30" height="50" uuid="036e9415-01db-4725-8eeb-467f4ae992ab"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[TOTAL]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="QuantityMesure" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{Quantity}]]></measureExpression>
</measure>
<measure name="street" class="java.lang.String" calculation="Nothing">
<measureExpression>$F{street}</measureExpression>
</measure>
<crosstabCell width="20" height="10">
<cellContents backcolor="#FFFFFF" mode="Opaque" style="cell">
<textField>
<reportElement x="0" y="0" width="20" height="10" uuid="ee3abbdf-bec7-4b0f-9d5a-7ed46e897fd0"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{QuantityMesure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="30" height="10" columnTotalGroup="ProductGroup">
<cellContents backcolor="#FFFF60" mode="Opaque" style="cell">
<textField>
<reportElement x="0" y="0" width="30" height="10" uuid="6747a993-1322-4432-ad74-dbbec94ee758"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{QuantityMesure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="80" height="10" columnTotalGroup="dummy">
<cellContents style="cell">
<textField>
<reportElement x="0" y="0" width="80" height="10"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{street}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</title>
</jasperReport>