9

JasperReports How to do pagination in Excel

 3 years ago
source link: https://www.codesd.com/item/jasperreports-how-to-do-pagination-in-excel.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

JasperReports How to do pagination in Excel

advertisements

I am trying to put page numbers/breaks at the bottom of each page and columns headers at the top, so when printed from Excel all pages are numbered and headed. It should not be such a big deal, right? But unfortunately it is, no matter what approach I tried I just cannot get the page number and page break at the bottom of the pages - they are anywhere else but at the bottom. I put "Page X of Y" in the Page Footer section, the Ignore Pagination is NOT checked, and when I generate the report I have Page X or Y after every 4 lines of data. I extended the page Height to 3-4 times of the standard height of Letter Landscape format, and that changed the footer to be printed after 18-20 lines of data - this is not a reliable way of adjusting it. Also I tried putting the Page Break with Print When expression set to print it every 20 lines, but that still it is not accurate, since on the first page I have less lines of data because of the Report Title - if I adjust it to be correct on the 1st page - it will print it somewhere in the middle on the next pages. Am I missing something obvious in the design how to put footer with page #s? Any help will be greatly appreciated.


I've solved this issue with help of net.sf.jasperreports.export.xls.fit.height parameter.

I set the report's height and net.sf.jasperreports.export.xls.fit.height report's property with the same value.

The sample:

<jasperReport ... pageWidth="595" pageHeight="800" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    ...
    <parameter name="net.sf.jasperreports.export.xls.fit.height" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA[800]]></defaultValueExpression>
    </parameter>
    ...
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{field1}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="100" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="433" y="0" width="80" height="20"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="513" y="0" width="40" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
</jasperReport>

The result (preview in MS Excel):

kmPG3.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK