How to Export Multiple Sheets from Jasper Report

Environment:

Jasper Studio 5.6.2, JDK 1.7

Step 1. Ensure Pagination NOT Ignored

<jasperReport ... isIgnorePagination="false" ...> 
 ... 
 </jasperReport>

Step 2. Configure Excel Exporter

<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="true"/>

Additionally, we'd better configure the IDE's excel exporter setting.

How to Export Multiple Sheets from Jasper Report_第1张图片

Step 3. Place Page Break

Do not forget to place page Break element on the place from where you want to split the page. <Break> is an item in the tool palette in Japser Studio.

Step 4. Ensure Sufficient Page Size
LESSON: If your page height is not big enough, your page break might not work.

Beware that big page height might cause a lot of empty rows, which would result in out of memory error, thus we need to handle the empty rows properly, like ignoring empty rows and meanwhile using a small dot for row place holder when we really want an empty row.

Step 5. Dynamic Sheet Name

According to reference [4], <Dynamic Sheet Names>, and its sample code, I added the following propertyExpression in my project and it works!

<staticText>
				<reportElement x="0" y="120" width="100" height="20" uuid="77d497e0-0cf0-4a2f-acf7-669f052721bd">
					<propertyExpression name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA[$F{customer_id}.toString()]]></propertyExpression>
				</reportElement>
				<textElement>
					<font isBold="true"/>
				</textElement>
				<text><![CDATA[Account ID]]></text>
			</staticText>


STEP 6: Jasper Server Setting

WEB-INF/classes/jasperreports.properties

# report exporter hints override export parameters
net.sf.jasperreports.export.parameters.override.report.hints=true
#com.jaspersoft.jrs.export.csv.paginated=true
com.jaspersoft.jrs.export.xls.paginated=true
#com.jaspersoft.jrs.export.pdf.paginated=false
#com.jaspersoft.jrs.export.docx.paginated=false
#com.jaspersoft.jrs.export.rtf.paginated=false
#com.jaspersoft.jrs.export.odt.paginated=false

net.sf.jasperreports.export.xls.one.page.per.sheet=true


WEB-INF/applicationContext.xml

<!-- export parameters -->
    
    <bean id="xlsExportParameters" class="com.jaspersoft.jasperserver.api.engine.jasperreports.common.XlsExportParametersBean">
        <property name="detectCellType" value="true"/>
        <property name="onePagePerSheet" value="true"/>
        <property name="removeEmptySpaceBetweenRows" value="false"/>
        <property name="removeEmptySpaceBetweenColumns" value="false"/>
        <property name="whitePageBackground" value="false"/>
        <property name="ignoreGraphics" value="false"/>
        <property name="collapseRowSpan" value="true"/>
        <property name="ignoreCellBorder" value="false"/>
        <property name="fontSizeFixEnabled" value="true"/>
        <property name="maximumRowsPerSheet" value="0"/>
        <property name="xlsFormatPatternsMap" ref="formatPatternsMap"/>
    </bean>


STEP 7: Jasper Server Excel Export Menu

Select the option <As Excel (Paginated) > !

Reference:

[1] http://jasperreports.sourceforge.net/api/net/sf/jasperreports/export/XlsReportConfiguration.html

[2] http://jasperreports.sourceforge.net/sample.reference/nopagebreak/

[3] http://helicaltech.com/blogs/split-excel-output-into-multiple-sheets/

[4] http://jasperreports.sourceforge.net/sample.reference/xlsfeatures/






你可能感兴趣的:(How to Export Multiple Sheets from Jasper Report)