在iReport中有许多单独的 - 未完成的数据集 [英] Having many separate - unrleated datasets in iReport

查看:93
本文介绍了在iReport中有许多单独的 - 未完成的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using iReport 2.0.4 to export some data to excel from a java application.

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

My problem is my subreports are grouping under the top level report but I want them to be discrete reports. Currently it looks like this

订单

    -Order Line 1
< br>     收据

        -Receipt Line 1

        -Receipt Line 2

     发票

         -Invoice Line 1

        -Invoice Line 2

订单

    -Order Line 2

     收据

        -Receipt Line 1

        ........

Order
   -Order Line 1
    Receipts
       -Receipt Line 1
       -Receipt Line 2
    Invoices
       -Invoice Line 1
       -Invoice Line 2
Order
   -Order Line 2
    Receipts
       -Receipt Line 1
       ........

我希望它在一个电子表格中成为3个单独的报告。喜欢这个

I want it to be 3 separate reports in one spreadsheet. Like this

订单

    所有订单行

收据

    所有收据行

发票

     所有发票行

Order
    all Order lines
Receipts
    all Receipt lines
Invoices
    all Invoice lines

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

Currently I have the Orders as the master report and the Receipts and Invoices as subreports, dropped into the detail band Orders.

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

What is the best way to get this layout, if it's possible at all?

推荐答案


  • 第一种方式。使用 JasperReports API

    • First way. Using JasperReports API
    • 您可以填写并编译三个单独的报告,然后使用 JRPdfExporterParameter.JASPER_PRINT_LIST 参数,用于使用以下代码构建单个报告:

      You can fill and compile three separate reports and then use JRPdfExporterParameter.JASPER_PRINT_LIST parameter for building the single report using code like this:

      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();
      

      你可以看看这个 JR 版本的样本 - 2.0.4 更多详情。

      You can look at this sample for your JR version - 2.0.4 for more details.


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

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

      You can add several datasets in iReport 4.x version to the single report. Every dataset may contain its own query. The list component can use its own dataset.

      在此示例中(使用 iReport 4.5构建。 1 )我已将3个 列表 组件放入标题频段:

      In this sample (build with iReport 4.5.1) I've placed 3 list components to the Title band:

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

      报告的设计是:

      < img src =https://i.stack.imgur.com/L4VRo.pngalt =报告在iReport中的设计>

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

      The result will be (via iReport preview):

      这篇关于在iReport中有许多单独的 - 未完成的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆