JasperReports:封面页

发布于 2024-08-04 01:44:18 字数 228 浏览 4 评论 0原文

我有一个 JasperReport,我想为此报告创建一个封面页。 封面页必须包含一些来自数据库的信息,例如公司名称等。 我试图使用子报告来做到这一点,但没有成功。 我创建了一个主报告,其中首先包含封面页作为子报告,然后 整个报告作为第二份子报告。我收到一份空报告。

我的第二次尝试是将封面页作为子报告放入主报告中,但是 这不太有效。

有任何提示如何执行此操作吗?


预先非常感谢。

I have a JasperReport and I want to create for this report a cover page.
The cover page must contain some information coming from the DB, like Company name, etc.
I am trying to do this using a subreport but I didn't succeed.
I've created a main report which contains first the cover page as a subreport and then
the whole report as a second subreport. I got an empty report.

My second try was to put inside the main report the cover page as a subreport but
this didn't work as well.

Any hint how to do this?

Thanks a lot in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

假情假意假温柔 2024-08-11 01:44:18

Directory Discourse

使用 Jasper Reports 设置子报表并非易事。至少有两种方法可以告诉主报表在哪里可以找到子报表。

  1. SUBREPORT_DIR 参数提供一个值。
  2. 将子报表放置在 CLASSPATH 中。

对于解决方案 1,在运行时确定主报告位置的绝对目录。然后,将子报表放置在主报表下的相关目录中。最后,告诉主报告包含子报告的子目录的绝对路径。

我没有使用解决方案2。

参数化主报表

考虑参数化主报表,而不是创建子报表。

  1. 将参数列表添加到报告中。
  2. 将参数拖到报告标题上。

如果您只有一份报告,但想要使用不同的徽标(以及公司名称、样式等),则可以使用参数来配置外观。

子报表用法

我发现当数据查​​询几乎相同但需要以稍微不同的方式对数据进行分组时创建子报表很有用。主报告包含所有常见内容(显示输入参数——以便可以重新创建报告、标题、公司名称、用户名、时间戳、页码等),而子报告则重点关注差异。通常,子报表会重叠,并且仅根据输入参数的值执行。

Directory Discourse

Setting up the subreport is not trivial using Jasper Reports. There are at least two ways to tell a master report where to find sub-reports.

  1. Provide a value for the SUBREPORT_DIR parameter.
  2. Place the subreports within the CLASSPATH.

For solution 1, determine the absolute directory of the master report location at run time. Then, place subreports in relative directories under the master report. Finally, tell the master report the absolute path to the subdirectory containing the subreports.

I have not used solution 2.

Parameterized Master

Consider parameterizing the master report, instead of creating subreports.

  1. Add a list of parameters to the report.
  2. Drag the parameters onto the report header.

If you only have one report, but want to use a different logo (and company name, styling, and so forth), then use parameters to configure the look and feel.

Subreport Usage

I find it useful to create subreports when the queries for the data are nearly the same, but need to group the data in slightly different ways. The master report contains everything that is common (showing input parameters -- so that the report can be recreated, headings, company name, user name, time stamp, page number, and so on), and the subreports focus on the differences. Often, the subreports will overlap and only be executed depending on the value of an input parameter.

流星番茄 2024-08-11 01:44:18

将它们添加到摘要区域,您甚至可以选择将其放在不同的页面上。
与您刚刚添加的子报告相比,您可以在他的摘要区域添加另一个子报告,
然后在他的身上再放一张,然后就可以了。您可以将无限的报告绑定在一起。

Add them to the summary band, you may even chose to have that on a different page.
Than on that subreport that you just added, at his summary band you can put another one,
and on his, another one and so you go. You can have infinite reports binded together.

静赏你的温柔 2024-08-11 01:44:18

我在标题带的末尾添加了一个中断。

<title>
   <band>
   <break></break>
   </band>
 </title>

这具有分页符的效果。

I added a break at the end of the title band.

<title>
   <band>
   <break></break>
   </band>
 </title>

This has the effect of a page break.

夏天碎花小短裙 2024-08-11 01:44:18

我可能误解了这个问题,因为接受的答案涉及阻止子报告,这是封面的完美解决方案(只需将其放在TITLE带中)。
子报表实际上是 JR 的杀手级功能。确实,它们并不简单,但无需对可用工具集进行任何调整或弯曲即可实现它们。
当数据集查询差异很大时,我会准确地使用它们......

I possibly misunderstood the question, because the accepted answer goes about discouraging subreports, which are the perfect solution for a cover (just put it in the TITLE band).
Subreports are actually the killer feature of JR. It's true they aren't simple, but they can be implemented without any tweaking nor bending of the available toolset.
And I use them EXACTLY when the dataset queries are widely different...

小红帽 2024-08-11 01:44:18

最近回答,但它可能会帮助另一个有点棘手的问题,

  • 右键单击“最大化带高度”的标题带,不要删除其他带

在此处输入图像描述

  • 标题栏也将是您的封面页,您可以添加任何内容你想要

  • 内容

    为每个页面添加您可以条件使用的组件(文本字段、图像、线条等)(int 打印表达式)

两页 jasper 报告的结帐示例

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928  -->
<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="with_cover_page" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="54476be0-8bb3-45ff-a01b-12ce691c960b">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="607" splitType="Stretch">
            <textField>
                <reportElement x="4" y="10" width="540" height="30" uuid="9a254956-a600-483d-a9fb-8d64ceb73766"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Some text header etc."]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="4" y="288" width="540" height="30" uuid="15a732d8-2596-433b-9ba6-4278c008a394"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Act like Body"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="4" y="560" width="540" height="30" uuid="1d4d4c98-4469-4001-a2ff-2e880846491e"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Act like Footer"]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch">
            <textField>
                <reportElement x="4" y="5" width="546" height="30" uuid="580f101d-9569-4692-914b-4f30e05df9a4">
                    <printWhenExpression><![CDATA[$V{PAGE_NUMBER} != 1]]></printWhenExpression>
                </reportElement>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="18"/>
                </textElement>
                <textFieldExpression><![CDATA["This is page Header for every page except first one"]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="4" y="49" width="546" height="30" uuid="52bcf471-555f-4fe7-bd35-a53aee7e761f"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="16"/>
                </textElement>
                <textFieldExpression><![CDATA["This is second page"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

这是源代码的预览

在此处输入图像描述
输入图片此处描述

Lately answer but It might help another one little bit tricky,

  • right click title band for "Maximized Band Height" dont delete other bands

enter image description here

  • Title band will be your cover page as well you can add whatever you want

  • the component (TextField,Image,Line etc.) for every page you can use conditionaly(int print expression)

Checkout Example for with two page jasper report

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928  -->
<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="with_cover_page" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="54476be0-8bb3-45ff-a01b-12ce691c960b">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="607" splitType="Stretch">
            <textField>
                <reportElement x="4" y="10" width="540" height="30" uuid="9a254956-a600-483d-a9fb-8d64ceb73766"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Some text header etc."]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="4" y="288" width="540" height="30" uuid="15a732d8-2596-433b-9ba6-4278c008a394"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Act like Body"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="4" y="560" width="540" height="30" uuid="1d4d4c98-4469-4001-a2ff-2e880846491e"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Act like Footer"]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch">
            <textField>
                <reportElement x="4" y="5" width="546" height="30" uuid="580f101d-9569-4692-914b-4f30e05df9a4">
                    <printWhenExpression><![CDATA[$V{PAGE_NUMBER} != 1]]></printWhenExpression>
                </reportElement>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="18"/>
                </textElement>
                <textFieldExpression><![CDATA["This is page Header for every page except first one"]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="4" y="49" width="546" height="30" uuid="52bcf471-555f-4fe7-bd35-a53aee7e761f"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="16"/>
                </textElement>
                <textFieldExpression><![CDATA["This is second page"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

This is preview ss for source code

enter image description here
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文