如何在一份报告中打印带有条形码或多个条形码的多份报告 [英] How to print several reports with barcode or several barcodes in one report

查看:27
本文介绍了如何在一份报告中打印带有条形码或多个条形码的多份报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 barcode 报告,它使用一个序列(Oracle 后端)来生成我的 barcode 数字.

I've got a barcode report which is using a sequence (Oracle backend) to generate my barcode numbers.

这是在我的查询中:

SELECT to_char(PALLET_ID_NO_SEQ.nextval) FROM dual

我将此字段放置在设计器窗口中,该窗口将显示 barcode 值.

I placed this field in designer window which will display the barcode value.

我有一张带有表情的图片:

I have an image with expression:

new com.pepkorit.BarbecueRotateRenderer(
    net.sourceforge.barbecue.BarcodeFactory.createCode128C(
    $F{TO_CHAR(PALLET_ID_NO_SEQ.NEXTVAL)}), false, true, 1, 50, 190, 50)

以上是使用序列值的barcode.

我希望能够打印/生成 100 份或更多报告.目前,我一次只能生成一份报告.

I want to be able to say to print/generate 100 or more reports. At this moment I'm able to generate only one report at a time.

所以我的第一个猜测是获取一个参数来提示用户一个值,该值将指示要打印多少个条形码,每个条形码都有一个单独的数字.

So my first guess is to get a parameter that prompts the user a value and that value will indicate how many barcodes to be printed and each with an individual number.

我不确定我关于解决这个问题的想法是否正确以及如何去做.

I'm not sure that my ideas about solving this problem are right and how to do it.

有人可以帮忙吗?

推荐答案

无需通过多种方式编程,只需对查询进行少量修改即可轻松完成.

It can be easily done with small modifying of your query without programming in several ways.

您可以使用单个报告的模板在一个报告中生成多个条形码.

You can use single report's template for generating several barcodes in one report.

在这种情况下,queryString 表达式(适用于 Oracle DB)将如下所示:

In this case the queryString expression (works for Oracle DB) will be like this:

SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}

- 它根据需要从序列中生成一个值.$P{quantity} 参数确定要生成的行数(条形码).

- it is generates a value from the sequence as many times as you need. The $P{quantity} parameter determines the number of rows (barcodes) to be generated.

工作 rjxml 文件:

<jasperReport ...>
    <parameter name="quantity" class="java.lang.Integer">
        <defaultValueExpression><![CDATA[20]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}]]>
    </queryString>
    <field name="BARCODE" class="java.lang.Integer"/>
    <field name="ROWNUM" class="java.lang.Integer"/>
    <title>
        <band height="82" splitType="Stretch">
            <textField>
                <reportElement x="145" y="18" width="240" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA["The number of barcodes is: " + $P{quantity}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <detail>
        <band height="47" splitType="Stretch">
            <componentElement>
                <reportElement x="145" y="10" width="200" height="28"/>
                <jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="2of7" drawText="false" checksumRequired="false">
                    <jr:codeExpression><![CDATA[$F{BARCODE}]]></jr:codeExpression>
                </jr:barbecue>
            </componentElement>
        </band>
    </detail>
</jasperReport>

结果将是 ($P{quantity} == 5):

The result will be ($P{quantity} == 5):

在您的情况下,queryString 表达式将如下所示:

In your case the queryString expression will be like this:

SELECT to_char(PALLET_ID_NO_SEQ.nextval) AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}

Barcode 组件的表达式为:

new com.pepkorit.BarbecueRotateRenderer(
    net.sourceforge.barbecue.BarcodeFactory.createCode128C($F{barcode}),
    false, true, 1, 50, 190, 50)

解决方案 2. 使用组头带

您可以使用与第一个解决方案相同的 queryString 表达式.rownum 字段上的组将帮助我们生成单个报告,其中包含许多属于自己组的条形码(一组 - 一个条形码).Barcode 组件应该放在 Group Header 带.

Solution 2. Using Group Header band

You can use the same queryString expression as in the first solution. The group on rownum field will help us to generate single report with many barcodes belonging to its own group (one group - one barcode). The Barcode component should be placed to the Group Header band.

使用 isStartNewPage 属性,我们可以管理是否在新页面上生成组.

Using the isStartNewPage property we can manage to generate group on new page or not.

rjxml 文件:

<jasperReport ...>
    <parameter name="quantity" class="java.lang.Integer">
        <defaultValueExpression><![CDATA[20]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}]]>
    </queryString>
    <field name="BARCODE" class="java.lang.Integer"/>
    <field name="ROWNUM" class="java.lang.Integer"/>
    <group name="rownumGroup" isStartNewPage="true">
        <groupExpression><![CDATA[$F{ROWNUM}]]></groupExpression>
        <groupHeader>
            <band height="50">
                <componentElement>
                    <reportElement x="145" y="11" width="200" height="28"/>
                    <jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="2of7" drawText="false" checksumRequired="false">
                        <jr:codeExpression><![CDATA[$F{BARCODE}]]></jr:codeExpression>
                    </jr:barbecue>
                </componentElement>
            </band>
        </groupHeader>
    </group>
    <title>
        <band height="82" splitType="Stretch">
            <textField>
                <reportElement x="145" y="18" width="240" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA["The number of barcodes is: " + $P{quantity}]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

如果 isStartNewPage="false" 对于组 rownumGroup,结果将是 ($P{quantity}== 7):

In case isStartNewPage="false" for group rownumGroup the result will be ($P{quantity}== 7):

如果 isStartNewPage="true" 对于组 rownumGroup,结果将是 ($P{quantity}== 5):

In case isStartNewPage="true" for group rownumGroup the result will be ($P{quantity} == 5):

我们可以将Subreport 组件添加到Detail 带(查看第一个解决方案)或组标题(参见第二个解决方案)乐队.在这种情况下,您不仅可以将 Barcode 组件添加到子报表中,还可以添加任何您想要的内容.

We can add Subreport component to the Detail band (see first solution) or Group Header (see second solution) band. In this case you can add to the subreport not only the Barcode component, but everything you want.

这篇关于如何在一份报告中打印带有条形码或多个条形码的多份报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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