目标是使用群组制作类似的东西
问题是我可以使用字段构建它,但是当我将从字段构建的报表(如大多数教程中)导出到Excel时,它变得一团糟。 我想使用表组件,可能部分,仅用于row1,row2 ......等所在的部分,因为表的导出相当不错。 这有可能吗? 如果我将一个表组件添加到详细信息区域中,它会显示每个组的整个表(所有行1-9都在每个组中,因此我根本没有分组),如下所示:
这是我的XML文件:
<?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="report1" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="8075ffe7-6e3e-430c-9792-0842e1047ee7">
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
<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="#EFF7FF"/>
</conditionalStyle>
</style>
<style name="table 1">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_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="#EFF7FF"/>
</conditionalStyle>
</style>
<subDataset name="New Dataset 1" uuid="6d70e59b-520c-4c3a-b122-fc299a1e36f3">
<queryString language="SQL">
<![CDATA[select * from test_table]]>
</queryString>
<field name="COLUMN1" class="java.lang.String"/>
<field name="INITIATOR" class="java.lang.String"/>
<field name="ID" class="java.lang.String"/>
<field name="URL" class="java.lang.String"/>
<field name="DOMAIN" class="java.lang.String"/>
</subDataset>
<queryString>
<![CDATA[select * from test_table]]>
</queryString>
<field name="COLUMN1" class="java.lang.String"/>
<field name="INITIATOR" class="java.lang.String"/>
<field name="ID" class="java.lang.String"/>
<field name="URL" class="java.lang.String"/>
<field name="DOMAIN" class="java.lang.String"/>
<group name="USER">
<groupExpression><![CDATA[$F{INITIATOR}]]></groupExpression>
<groupHeader>
<band height="20">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="f3c7aeda-d5fc-4745-aa57-6b86527bca7d"/>
<textFieldExpression><![CDATA[$F{INITIATOR}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="82" splitType="Stretch">
<componentElement>
<reportElement key="table 1" style="table 1" x="0" y="0" width="802" height="80" uuid="1e1e5c70-7231-407c-8a21-8a8abe18004c"/>
<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="New Dataset 1" uuid="c1fc144a-34ea-4a3c-bad5-979e248dbdd5">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="164" uuid="6fc1588c-ff53-457e-9ded-bf2ef1499ef9">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="164" height="30" uuid="37471666-30cf-4fba-a25a-2341517a9ff8"/>
<text><![CDATA[COLUMN1]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="164" height="20" uuid="23a35d1a-1835-4f98-b948-2e20d170b7cb"/>
<textFieldExpression><![CDATA[$F{COLUMN1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="143" uuid="3bb44350-b9a3-42f3-a4b4-24cc92c1ac7a">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="143" height="30" uuid="32882a4d-9af7-4d20-bffc-d97304f852ec"/>
<text><![CDATA[INITIATOR]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="143" height="20" uuid="624c6056-9c8d-469d-834e-052e7ba64205"/>
<textFieldExpression><![CDATA[$F{INITIATOR}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="145" uuid="fdc25f77-cbf8-437b-9599-8dac13c231c7">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="145" height="30" uuid="9def11e0-f333-4af6-acd2-87693f546b94"/>
<text><![CDATA[ID]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="145" height="20" uuid="bffecf39-515f-49fa-a2fd-dce3b899664a"/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="215" uuid="ebcc9292-c0f8-45d7-acfb-a0cd07411c06">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="215" height="30" uuid="119558f5-9f63-408d-88fe-685bff93420c"/>
<text><![CDATA[URL]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="215" height="20" uuid="57fb4ae3-2ef8-46f5-9078-189afba2cc6f"/>
<textFieldExpression><![CDATA[$F{URL}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="134" uuid="f241a40c-8426-4b4f-ad01-fcda25e3891c">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="134" height="30" uuid="d3015f10-9258-4ac9-8e95-a00f450b751e"/>
<text><![CDATA[DOMAIN]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="134" height="20" uuid="fab1275a-7ae9-443b-8861-fa7c319e01b1"/>
<textFieldExpression><![CDATA[$F{DOMAIN}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
答案 0 :(得分:1)
我已经编辑了你的jrxml。我将id从主查询传递给表组件作为参数,并在查询where条件时使用它,因此表查询将只返回与父查询id相关的行。
<?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="report1" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="125"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
<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="#EFF7FF"/>
</conditionalStyle>
</style>
<style name="table 1">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_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="#EFF7FF"/>
</conditionalStyle>
</style>
<subDataset name="New Dataset 1">
<parameter name="id" class="java.lang.Integer">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from test_table where id = $P{id};]]>
</queryString>
<field name="COLUMN1" class="java.lang.String"/>
<field name="INITIATOR" class="java.lang.String"/>
<field name="ID" class="java.lang.String"/>
<field name="URL" class="java.lang.String"/>
<field name="DOMAIN" class="java.lang.String"/>
</subDataset>
<queryString>
<![CDATA[select * from test_table;]]>
</queryString>
<field name="COLUMN1" class="java.lang.String"/>
<field name="INITIATOR" class="java.lang.String"/>
<field name="ID" class="java.lang.String"/>
<field name="URL" class="java.lang.String"/>
<field name="DOMAIN" class="java.lang.String"/>
<group name="USER">
<groupExpression><![CDATA[$F{INITIATOR}]]></groupExpression>
<groupHeader>
<band height="20">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textFieldExpression><![CDATA[$F{INITIATOR}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="82" splitType="Stretch">
<componentElement>
<reportElement key="table 1" style="table 1" x="0" y="0" width="802" height="80"/>
<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="New Dataset 1">
<datasetParameter name="id">
<datasetParameterExpression><![CDATA[$F{ID}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="164">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="164" height="30"/>
<text><![CDATA[COLUMN1]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="164" height="20"/>
<textFieldExpression><![CDATA[$F{COLUMN1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="143">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="143" height="30"/>
<text><![CDATA[INITIATOR]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="143" height="20"/>
<textFieldExpression><![CDATA[$F{INITIATOR}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="145">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="145" height="30"/>
<text><![CDATA[ID]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="145" height="20"/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="215">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="215" height="30"/>
<text><![CDATA[URL]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="215" height="20"/>
<textFieldExpression><![CDATA[$F{URL}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="134">
<jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="134" height="30"/>
<text><![CDATA[DOMAIN]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="table 1_CH" height="30" rowSpan="1"/>
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="134" height="20"/>
<textFieldExpression><![CDATA[$F{DOMAIN}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>