【问题标题】:Multiple Jasper repports page number handler with key多个 Jasper 使用键报告页码处理程序
【发布时间】:2018-05-01 01:45:50
【问题描述】:

大家好,stackoverflowers,

我有 2 份碧玉报告。两者都从零页码开始。我希望我的第二份报告从第一个碧玉报告的总页数 + 1 开始。我已经看到了关于这个主题的很好的解决方案 herethere 但这不是我想要的。我想处理我的 jasper 报告,例如带有 id 的 html 标记,然后借助这个 id,获取我的 textField 并更改我的 java 代码中的页码值。

例如我的文本框是这样的:

<textField>
    <reportElement  x="520" y="1" width="40" height="48" uuid="5df12c06-9c58-4b26-99c1-02b1d8e86456"/>
    <box>
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    </box>
    <textElement textAlignment="Center" verticalAlignment="Middle"/>
    <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>

【问题讨论】:

    标签: java jasper-reports


    【解决方案1】:

    我有同样的问题这就是我解决它的方法。在您的文本文件中,您需要一个密钥。这将是您的 id。你应该有这样的东西:

    <textField>
        <reportElement key="textFieldCurrentPage" x="520" y="1" width="40" height="48" uuid="5df12c06-9c58-4b26-99c1-02b1d8e86456"/>
        <box>
            <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
        </box>
        <textElement textAlignment="Center" verticalAlignment="Middle"/>
        <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
    </textField>
    

    在你的 java 代码中你可以有类似的东西:

    // create your second jasper print
    JasperPrint jasperPrint = JasperFillManager.fillReport(..., ..., ...);
    
    List<JRPrintPage> listPages = jasperPrint.getPages();
    int numberOfPages = listPages.size();
    int currentPageIndex = 1;
    for (JRPrintPage currentPage : listPages) {
        List listElements = currentPage.getElements();
    
        for (Object element : listElements) {
            if (element instanceof JRTemplatePrintText) {
                JRTemplatePrintText templatePrintText = (JRTemplatePrintText) element;
                // set currrent page
                if (templatePrintText.getKey() != null
                        && templatePrintText.getKey().equalsIgnoreCase("textFieldCurrentPage")) {
                        templatePrintText.setText(String.valueOf(lastPageNumber + currentPageIndex));
                }
            }
        }
        currentPageIndex++;
    }
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多