gpt4 book ai didi

java - 在 iReport 中有许多独立的、未处理的数据集

转载 作者:搜寻专家 更新时间:2023-11-01 01:45:37 25 4
gpt4 key购买 nike

我正在使用 iReport 2.0.4 将一些数据从 Java 应用程序导出到 Excel。

我的问题是我的子报表在顶级报表下分组,但我希望它们是离散报表。目前看起来像这样

订单
-订单行 1
收据
-收据行 1
-收据行 2
发票
-发票行 1
-发票行 2
订单
-订单行 2
收据
-收据行 1
........

我希望它是一个电子表格中的 3 个独立报告。像这样

订单
所有订单行
收据
所有收据行
发票
所有发票行

目前,我将订单作为主报表,将收据和发票作为子报表,放入详细信息带订单中。

如果可能的话,获得此布局的最佳方法是什么?

最佳答案

您可以填写和编译三个单独的报告,然后使用 JRPdfExporterParameter.JASPER_PRINT_LIST使用如下代码构建单个报告的参数:

JasperReport ordersReport = JasperCompileManager.compileReport(srcOrdersReport);
JasperPrint jpOrdersReport = JasperFillManager.fillReport(ordersReport, ordersParamsMap, ordersDataSource);

JasperReport receiptsReport = JasperCompileManager.compileReport(srcReceiptsReport);
JasperPrint jpReceiptsReport = JasperFillManager.fillReport(receiptsReport, receiptsParamsMap, receiptsDataSource);

JasperReport invoicesReport = JasperCompileManager.compileReport(srcInvoicesReport);
JasperPrint jpInvoicesReport = JasperFillManager.fillReport(invoicesReport, invoicesParamsMap, invoicesDataSource);

List<JasperPrint> printList = new ArrayList<JasperPrint>();

printList.add(jpOrdersReport);
printList.add(receiptsReport);
printList.add(invoicesReport);

JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, printList);

exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, output);
exporter.exportReport();

可以看看这个sample for your JR version - 2.0.4了解更多详情。

  • 第二种方式。使用多个数据集和列表组件

您可以在iReport 4.x 版本中将多个数据集添加到单个报告中。每个数据集都可能包含自己的查询。 list 组件可以使用自己的数据集。

在此示例中(使用 iReport 4.5.1 构建)我将 3 个list 组件放置到Title乐队:

<?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="several_queries" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<subDataset name="OrdersDataset">
<queryString>
<![CDATA[SELECT TOP 5 ORDERID AS orderId, SHIPNAME AS orderShipName, SHIPCOUNTRY AS orderShipCounty, SHIPCITY AS orderShipCity
FROM orders]]>
</queryString>
<field name="ORDERID" class="java.lang.Integer"/>
<field name="ORDERSHIPNAME" class="java.lang.String"/>
<field name="ORDERSHIPCOUNTY" class="java.lang.String"/>
<field name="ORDERSHIPCITY" class="java.lang.String"/>
</subDataset>
<subDataset name="ReceiptsDataset">
<queryString>
<![CDATA[SELECT TOP 10 ID AS receiptId, CITY AS receiptCity FROM receipts]]>
</queryString>
<field name="RECEIPTID" class="java.lang.Integer"/>
<field name="RECEIPTCITY" class="java.lang.String"/>
</subDataset>
<subDataset name="InvoicesDataset">
<queryString>
<![CDATA[SELECT TOP 7 ID AS invoiceId, TOTAL AS invoiceSum FROM invoices]]>
</queryString>
<field name="INVOICEID" class="java.lang.Integer"/>
<field name="INVOICESUM" class="java.math.BigDecimal"/>
</subDataset>
<subDataset name="dataset1"/>
<queryString>
<![CDATA[SELECT 1 as t FROM dual WHERE 1=2]]>
</queryString>
<field name="t" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="243" splitType="Stretch">
<componentElement>
<reportElement positionType="Float" x="0" y="44" width="555" height="19"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="OrdersDataset">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="19" width="555">
<textField>
<reportElement x="0" y="0" width="100" height="19"/>
<box leftPadding="10" rightPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{ORDERID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="19"/>
<box leftPadding="10" rightPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{ORDERSHIPNAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="0" width="100" height="19"/>
<box leftPadding="10" rightPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{ORDERSHIPCOUNTY}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="300" y="0" width="100" height="19"/>
<box leftPadding="10" rightPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{ORDERSHIPCITY}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<componentElement>
<reportElement positionType="Float" x="0" y="130" width="400" height="18"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="ReceiptsDataset">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="18" width="400">
<textField>
<reportElement positionType="Float" x="100" y="0" width="100" height="18"/>
<box leftPadding="10" rightPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{RECEIPTCITY}]]></textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="0" y="0" width="100" height="18"/>
<box leftPadding="10" rightPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{RECEIPTID}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<staticText>
<reportElement positionType="Float" x="0" y="4" width="400" height="20"/>
<box topPadding="1" leftPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Orders]]></text>
</staticText>
<staticText>
<reportElement x="0" y="24" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isItalic="true"/>
</textElement>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement x="100" y="24" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isItalic="true"/>
</textElement>
<text><![CDATA[Customer name]]></text>
</staticText>
<staticText>
<reportElement x="200" y="24" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isItalic="true"/>
</textElement>
<text><![CDATA[Customer country]]></text>
</staticText>
<staticText>
<reportElement x="300" y="24" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isItalic="true"/>
</textElement>
<text><![CDATA[Customer city]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" x="0" y="109" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isItalic="true"/>
</textElement>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" x="100" y="109" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isItalic="true"/>
</textElement>
<text><![CDATA[City]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" x="0" y="89" width="200" height="20"/>
<box topPadding="1" leftPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Receipts]]></text>
</staticText>
<componentElement>
<reportElement positionType="Float" x="0" y="201" width="400" height="18"/>
<jr:list 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="InvoicesDataset">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="18" width="400">
<textField pattern="###0.00;-###0.00">
<reportElement positionType="Float" x="100" y="0" width="100" height="18"/>
<box leftPadding="10" rightPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{INVOICESUM}]]></textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="0" y="0" width="100" height="18"/>
<box leftPadding="10" rightPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{INVOICEID}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<staticText>
<reportElement positionType="Float" x="0" y="161" width="200" height="20"/>
<box topPadding="1" leftPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Invoices]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" x="100" y="181" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isItalic="true"/>
</textElement>
<text><![CDATA[Sum]]></text>
</staticText>
<staticText>
<reportElement positionType="Float" x="0" y="181" width="100" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isItalic="true"/>
</textElement>
<text><![CDATA[ID]]></text>
</staticText>
</band>
</title>
</jasperReport>

报告的设计是:

The report's design in iReport

结果将是(通过 iReport 预览):

The report's result

关于java - 在 iReport 中有许多独立的、未处理的数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11604391/

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