如何在最后一页上隐藏页眉标题

时间:2014-06-03 19:05:35

标签: variables jasper-reports

我认为我的评估时间有问题。在此示例中,您会看到正确反映最后一页的变量$P{REPORT_PARAMETERS_MAP}.get("LastPageNumber");它正确更新。但是当我将它用于详细频段(实验)的“printWhenExpression”或页面标题带(我的目标)时,它不起作用。

我正在使用“页面”评估时间,其中似乎适用于变量本身。但printWhenExpressions无法使用此变量。

这是我的xml文件:

<?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="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <queryString>
        <![CDATA[select * from users]]>
    </queryString>
    <field name="userName" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <pageHeader>
        <band height="23" splitType="Stretch">
            <textField evaluationTime="Page">
                <reportElement x="120" y="0" width="238" height="20">
                    <printWhenExpression><![CDATA[!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
            .get("LastPageNumber"))]]></printWhenExpression>
                </reportElement>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["please don't print on last page - page header"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Page">
                <reportElement x="380" y="0" width="175" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["last page  variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
            .get("LastPageNumber"))]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="2" y="2" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["Page header"]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <detail>
        <band height="21" splitType="Stretch">
            <textField evaluationTime="Page">
                <reportElement x="381" y="0" width="174" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
            .get("LastPageNumber"))]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{userName}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Page">
                <reportElement x="119" y="0" width="191" height="20">
                    <printWhenExpression><![CDATA[!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
            .get("LastPageNumber"))]]></printWhenExpression>
                </reportElement>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["please don't print on last page - detail"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <lastPageFooter>
        <band height="50">
            <line>
                <reportElement x="188" y="21" width="100" height="1">
                    <printWhenExpression><![CDATA[new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",
    $V{PAGE_NUMBER}))]]></printWhenExpression>
                </reportElement>
            </line>
            <textField evaluationTime="Page">
                <reportElement x="380" y="2" width="174" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["last page variable is: " + $V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}
            .get("LastPageNumber"))]]></textFieldExpression>
            </textField>
        </band>
    </lastPageFooter>
</jasperReport>

我的解决方案是制作两个报告(一个用于最后一页),然后使用jasper导出器的数组列表选项加入它们(jasperPrints):

List jasperPrintList = new ArrayList();

JasperPrint jasperPrint1 =
        JasperFillManager.fillReport(
            jasperReport1,
            parameters,
            c
    );


JasperPrint jasperPrint2 =
        JasperFillManager.fillReport(
            jasperReport2,
            parameters,
            c
    );
jasperPrintList.add(jasperPrint1);
jasperPrintList.add(jasperPrint2);
JRPdfExporter exporter = new JRPdfExporter();
ByteArrayOutputStream byte_report = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "test_report_name");
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, byte_report);
exporter.exportReport();

0 个答案:

没有答案