【问题标题】:inserting break in table to print only 10 rows per page in jasper reports 3.7.2在表中插入中断以在 jasper 报告 3.7.2 中每页仅打印 10 行
【发布时间】:2014-12-30 19:24:27
【问题描述】:

我有一个以表格格式打印报告的 jasper 代码,并且报告的值在运行时从 java 类传递,我正在使用 jasper 报告 3.7.2 jar 来打印报告。 jasper代码如下:

<?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="grouping_on_zipcode_basis" pageWidth="1400" pageHeight="750" orientation="Landscape" isIgnorePagination="true" columnWidth="1300" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" >
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="ireport.scriptlethandling" value="0"/>
    <property name="ireport.encoding" value="UTF-8"/>
    <import value="net.sf.jasperreports.engine.*"/>
    <import value="java.util.*"/>
    <import value="net.sf.jasperreports.engine.data.*"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" forecolor="#FFFFFF" backcolor="#006F3A">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#57A7E8">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
        <conditionalStyle>
            <conditionExpression><![CDATA[Boolean.valueOf($V{REPORT_COUNT}.intValue() % 2 == 0)]]></conditionExpression>
            <style backcolor="#FFFFFF"/>
        </conditionalStyle>
    </style>
    <subDataset name="tableDataset" >
        <field name="participantName" class="java.lang.String"/>
        <field name="Ssn" class="java.lang.String"/>
        <field name="Zipcode" class="java.lang.String"/>
    </subDataset>
        <field name="Ssn" class="java.lang.String"/>
        <field name="Zipcode" class="java.lang.String"/>
    <background>
        <band />
    </background>
    <title>
        <band height="200">
            <componentElement>
                <reportElement key="table" style="table" x="146" y="150" width="299" height="46" isRemoveLineWhenBlank="true" />
                <jr:table 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="tableDataset">
                        <datasetParameter name="REPORT_DATA_SOURCE">
                           <datasetParameterExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></datasetParameterExpression>
                        </datasetParameter>
                    </datasetRun>
                    <jr:column width="90" >
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30" />
                                <text><![CDATA[PARTICIPANT NAME]]></text></staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20" >
                                </reportElement>
                                <textFieldExpression><![CDATA[$F{participantName}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90" >
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30" >
                                <printWhenExpression><![CDATA[new Boolean($F{Ssn}!= null)]]></printWhenExpression>
                                </reportElement>
                                <text><![CDATA[SSN]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField isBlankWhenNull="true">
                                <reportElement isRemoveLineWhenBlank="true" x="0" y="0" width="90" height="20" />
                                <textFieldExpression><![CDATA[$F{Ssn}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90" >
                            <printWhenExpression><![CDATA[new Boolean($F{Zipcode}!= null)]]></printWhenExpression>
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30" >
                                    <printWhenExpression><![CDATA[new Boolean($F{Zipcode}!= null)]]></printWhenExpression>
                                </reportElement>
                                <text><![CDATA[ZIPCODE]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField isBlankWhenNull="true">
                                <reportElement isRemoveLineWhenBlank="true" x="0" y="0" width="90" height="20" />
                                <textFieldExpression><![CDATA[$F{participantZip}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
        </title>
    <columnFooter>
        <band />
    </columnFooter>
    <pageFooter>
        <band />
    </pageFooter>
    <summary>
        <band />
    </summary>
</jasperReport>

现在我只想在每个表中打印 10 行,并且必须在下一页的新表上打印即将到来的值,然后继续。但所有表必须只包含 10 行。请帮帮我..!

【问题讨论】:

    标签: jasper-reports


    【解决方案1】:

    我找到了办法。我们可以使用“print when expression”在详细信息单元格的末尾插入一个分栏符。代码如下:

    <jr:detailCell style="table_TD" height="30" rowSpan="1">
                                <textField>
                                    <reportElement x="0" y="0" width="90" height="18"/>
                                    <textElement/>
                                    <textFieldExpression class="java.lang.String"><![CDATA[$F{participantName}]]></textFieldExpression>
                                </textField>
                                <break type="Column">
                                    <reportElement x="0" y="19" width="90" height="1">
                                        <printWhenExpression><![CDATA[new java.lang.Boolean((int)($V{REPORT_COUNT}.intValue())%10==0)]]></printWhenExpression>
                                    </reportElement>
                                </break>
                            </jr:detailCell>
    

    【讨论】:

    • 谢谢。我想用 ireport 限制每页的行数。这确实有帮助。
    猜你喜欢
    • 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
    相关资源
    最近更新 更多