我们正在从 Ext JS UI生成 Excel 报告,该报告包含一些过滤器参数和一个按照所选过滤器获取数据的按钮。数据显示在过滤器组件下方的 Ext JS 网格中。在导出数据期间,过滤器参数将放在 Excel 的工作表1和要放入工作表2中的数据。这适用于 JasperReports jar 4.7.0但是使用 JR jar 5.1.2,过滤器详细信息和数据在同一个工作表中。请注意,没有代码更改,只是jar已更改。
如果我遗失了什么,请告诉我。
下面是jrxml和几行 Java 代码:
<?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="REPORT TITLE" pageWidth="1400" pageHeight="800" columnWidth="1360" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryWithPageHeaderAndFooter="true" isIgnorePagination="true">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="851"/>
<property name="ireport.y" value="0"/>
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="true"/>
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
<property name="net.sf.jasperreports.export.xlsx.detect.cell.type" value="true"/>
<property name="net.sf.jasperreports.export.xls.sheet.names.all" value="Filter Criteria/REPORT TITLE"/>
<style name="table 2_CH" isDefault="true" mode="Opaque">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<paragraph leftIndent="2" rightIndent="2"/>
</style>
<style name="table 3_CH" mode="Opaque" isBold="true"/>
<subDataset name="Table Dataset 1">
<parameter name="reportDataSrc" class="java.lang.Object">
<parameterDescription><![CDATA[reportDataSrc]]></parameterDescription>
</parameter>
<field name="xxx" class="java.lang.Object">
<fieldDescription><![CDATA[xxx]]></fieldDescription>
</field>
</subDataset>
<parameter name="reportTitle" class="java.lang.String"/>
<parameter name="dataSrc" class="java.util.List">
<parameterDescription><![CDATA[dataSrc]]></parameterDescription>
</parameter>
<parameter name="Filter_Information" class="net.sf.jasperreports.engine.JasperReport">
<parameterDescription><![CDATA[Filter_Information]]></parameterDescription>
</parameter>
<parameter name="filterInformationSrc" class="java.util.List">
<parameterDescription><![CDATA[filterInformationSrc]]></parameterDescription>
</parameter>
<parameter name="fileType" class="java.lang.String">
<parameterDescription><![CDATA[fileType]]></parameterDescription>
</parameter>
<parameter name="user" class="java.lang.Object">
<parameterDescription><![CDATA[user]]></parameterDescription>
</parameter>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band/>
</title>
<pageFooter>
<band height="10">
<textField evaluationTime="Report">
<reportElement style="table 3_CH" positionType="Float" x="765" y="0" width="120" height="10" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new java.lang.Boolean($P{fileType} != null && $P{fileType}.equalsIgnoreCase("PDF") )]]></printWhenExpression>
</reportElement>
<textElement>
<font fontName="Arial" size="8" isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA["User : " + ($P{user})]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table 3_CH" positionType="Float" x="985" y="0" width="74" height="10" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new java.lang.Boolean($P{fileType} != null && $P{fileType}.equalsIgnoreCase("PDF") )]]></printWhenExpression>
</reportElement>
<textElement textAlignment="Right">
<font fontName="Arial" size="8" isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA["Page "+($V{PAGE_NUMBER}.intValue())+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement style="table 3_CH" positionType="Float" x="1059" y="0" width="21" height="10" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new java.lang.Boolean($P{fileType} != null && $P{fileType}.equalsIgnoreCase("PDF") )]]></printWhenExpression>
</reportElement>
<textElement>
<font fontName="Arial" size="8" isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA[" " + ($V{PAGE_NUMBER}.intValue())]]></textFieldExpression>
</textField>
<textField pattern="dd-MMM-yyyy h.mm a">
<reportElement style="table 3_CH" positionType="Float" x="1180" y="0" width="120" height="10" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new java.lang.Boolean($P{fileType} != null && $P{fileType}.equalsIgnoreCase("PDF") )]]></printWhenExpression>
</reportElement>
<textElement>
<font fontName="Arial" size="8" isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band height="48" splitType="Stretch">
<subreport>
<reportElement positionType="Float" mode="Opaque" x="0" y="0" width="600" height="1" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new java.lang.Boolean($P{filterInformationSrc} != null && $P{filterInformationSrc}.size() > 0 )]]></printWhenExpression>
</reportElement>
<subreportParameter name="filterInformationSrc">
<subreportParameterExpression><![CDATA[$P{filterInformationSrc}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[(new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{filterInformationSrc}))]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{Filter_Information}]]></subreportExpression>
</subreport>
<break>
<reportElement positionType="Float" x="0" y="1" width="100" height="1" isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[new java.lang.Boolean($P{fileType} != null && $P{fileType}.equalsIgnoreCase("Excel") && $P{filterInformationSrc} != null && $P{filterInformationSrc}.size() > 0 )]]></printWhenExpression>
</reportElement>
</break>
<componentElement>
<reportElement key="" style="table 2_CH" positionType="Float" x="0" y="6" width="1360" height="42" isPrintWhenDetailOverflows="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="Table Dataset 1">
<datasetParameter name="reportDataSrc">
<datasetParameterExpression><![CDATA[$P{dataSrc}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[(new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{dataSrc}))]]></dataSourceExpression>
</datasetRun>
<jr:column width="151">
<jr:columnHeader style="table 2_CH" height="25" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="151" height="25" backcolor="#99CCFF"/>
<textElement textAlignment="Left" verticalAlignment="Top">
<font fontName="Arial" size="9" isBold="true"/>
</textElement>
<text><![CDATA[xxx]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 2_CH" height="25" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="151" height="25"/>
<textElement textAlignment="Left" verticalAlignment="Top">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{xxx}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>
加载jrxml
JasperDesign jasperDesignObj = JRXmlLoader.load(ReportUtil.getJRXMLResourcePath(reportType, CommonConstants.JRXML_EXTENSION));
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataProviderList);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesignObj);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);
jasperPrint.getPages()。size()返回2 4.7.1但1返回5.1.2,不知道这是怎么回事。
属性集:
if (CommonConstants.FILE_TYPE_EXCEL.equals(fileType)) {
parameters.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
parameters.put(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
parameters.put(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
parameters.put(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
parameters.put(JRXlsExporterParameter.IGNORE_PAGE_MARGINS, Boolean.TRUE);
}