在JasperReports中,如何在xlsx导出中包含一个“空白”行?

时间:2017-05-12 20:07:08

标签: jasper-reports export-to-excel jasperserver

我遇到了从JasperReports Server导出到xlsx的数据格式问题(v 6.3.0,build 20160621_1840)。考虑一个包含以下内容的报告:

  1. 与选定的报告参数相关的一些标题信息
  2. 将标题与数据分开的空白行
  3. 包含在给定所选参数的情况下返回的数据的表
  4. 理想的行为是,在xlsx导出时,用户可以单击单个数据单元并单击排序(或按ctrl + t创建数据表等),而不会自动尝试将标题信息作为一部分包含在内排序(数据表等)。问题是在xlsx导出时,Jasper拒绝真正创建“空白”行,这意味着操作扩展到所有报告带,而不仅仅是数据带:

    The operation extends to all report bands, not just the data band.

    正如您所看到的,如果我在单个数据单元格中按下ctrl + t,则选择范围扩展到#1和#2,但所需的行为是使其仅包含#3。

    我尝试了以下内容:

    • 在标题信息下方添加额外空格
    • 将空文本字段放入该区域
    • 明确将该文本字段的值设置为null
    • 检查“空时为空”选项
    • 在标题信息下添加空框
    • 将空文本字段放入该框架等
    • 在标题和数据带之间的新频段中尝试以上所有内容
    • 通过将其设置为TRUE()
    • 来播放“Print When Expression”

    在上述方案中,在xlsx导出时,添加的行(#2)不会出现,或者它会出现但不是“空白”,如下所示。

    Blank row containing an empty cell that is not actually "blank"

    据推测,它包含一个空字符串。只需进入和退出单元格即可将其清空。

    请注意,Jaspersoft Studio的导出按预期(大部分)运行。如上所述,问题是在部署到JasperReports Server之后保留导出时的空白行。特别是,问题在于xlsx导出,而不是xls导出。

    下面的报告的简化版本(服务器信息被剥离)演示了我尝试在数据周围创建空行的一些不同策略。下面的表格显示了从JasperReports Server导出以下报告时发生的情况:

    export format | empty header row? | empty footer row?
    =====================================================
         xls      |        yes        |        no        
         xlsx     |        no         |        no        
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1  -->
    <!-- 2017-05-17T09:49:04 -->
    <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="Single_Amount" pageWidth="600" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="600" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="2c25db5f-6fb0-41a2-8a3a-894bafd6d9d4">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.unit." value="pixel"/>
        <property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
        <style name="Table_TH" mode="Opaque" backcolor="#8FAFCC">
            <box>
                <pen lineWidth="0.5" lineColor="#8A8383"/>
                <topPen lineWidth="0.5" lineColor="#8A8383"/>
                <leftPen lineWidth="0.5" lineColor="#8A8383"/>
                <bottomPen lineWidth="0.5" lineColor="#8A8383"/>
                <rightPen lineWidth="0.5" lineColor="#8A8383"/>
            </box>
        </style>
        <style name="Table_CH" mode="Opaque" backcolor="#CFDBE6">
            <box>
                <pen lineWidth="0.5" lineColor="#8A8383"/>
                <topPen lineWidth="0.5" lineColor="#8A8383"/>
                <leftPen lineWidth="0.5" lineColor="#8A8383"/>
                <bottomPen lineWidth="0.5" lineColor="#8A8383"/>
                <rightPen lineWidth="0.5" lineColor="#8A8383"/>
            </box>
        </style>
        <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#8A8383"/>
                <topPen lineWidth="0.5" lineColor="#8A8383"/>
                <leftPen lineWidth="0.5" lineColor="#8A8383"/>
                <bottomPen lineWidth="0.5" lineColor="#8A8383"/>
                <rightPen lineWidth="0.5" lineColor="#8A8383"/>
            </box>
            <conditionalStyle>
                <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
                <style backcolor="#E3EBF2"/>
            </conditionalStyle>
        </style>
        <subDataset name="db" uuid="ac48b023-08c7-4a89-9bbd-551911707109">
            <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
            <queryString language="SQL">
                <![CDATA[select 'John' "First Name", 'Smith' "Last Name", '' "Organization Name" from dual]]>
            </queryString>
            <field name="First Name" class="java.lang.String"/>
            <field name="Last Name" class="java.lang.String"/>
            <field name="Organization Name" class="java.lang.String"/>
        </subDataset>
        <queryString>
            <![CDATA[select 'John' "First Name", 'Smith' "Last Name", '' "Organization Name" from dual]]>
        </queryString>
        <field name="First Name" class="java.lang.String"/>
        <field name="Last Name" class="java.lang.String"/>
        <field name="Organization Name" class="java.lang.String"/>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band height="45">
                <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                <frame>
                    <reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="600" height="45" uuid="5134c566-280b-45b1-bab7-c44956531a4f">
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.y" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                    </reportElement>
                    <textField isStretchWithOverflow="true">
                        <reportElement x="0" y="0" width="600" height="15" uuid="8307c6e8-567d-466f-8e7f-1c85c5acee3d">
                            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                        </reportElement>
                        <textElement textAlignment="Left" verticalAlignment="Middle">
                            <font size="11" isBold="false"/>
                        </textElement>
                        <textFieldExpression><![CDATA["Transactions involving at least 25.00 USD"]]></textFieldExpression>
                    </textField>
                    <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                        <reportElement positionType="FixRelativeToBottom" x="0" y="15" width="200" height="15" uuid="2b678b6b-4553-497f-aa2d-ef886011c7f9">
                            <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                            <property name="com.jaspersoft.studio.unit.y" value="pixel"/>
                            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                        </reportElement>
                    </textField>
                </frame>
            </band>
        </title>
        <detail>
            <band height="61">
                <componentElement>
                    <reportElement positionType="Float" x="0" y="0" width="600" height="61" uuid="7ed23a83-5028-42ce-9cb0-10a2e4ad5d98">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                    </reportElement>
                    <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" whenNoDataType="AllSectionsNoDetail">
                        <datasetRun subDataset="db" uuid="595295a2-96d8-4b04-a595-95844237815b">
                            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                        </datasetRun>
                        <jr:column width="200" uuid="8c6f9d1f-c20e-4aaf-9a04-1a66e5adf7dd">
                            <property name="com.jaspersoft.studio.components.table.model.column.name"/>
                            <jr:columnHeader style="Table_CH" height="30">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <staticText>
                                    <reportElement x="0" y="0" width="200" height="30" uuid="40c088be-aac3-41f2-9dce-d0e4741d306a"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12"/>
                                    </textElement>
                                    <text><![CDATA[First Name]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="200" height="30" uuid="df14df5e-df01-4b69-811e-895d5846eb80">
                                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                                    </reportElement>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="11"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{First Name}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="200" uuid="17860d95-195a-4303-b64b-79ea1180e369">
                            <property name="com.jaspersoft.studio.components.table.model.column.name"/>
                            <jr:columnHeader style="Table_CH" height="30">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <staticText>
                                    <reportElement x="0" y="0" width="200" height="30" uuid="22c004ba-6b97-4979-a33c-bbe565df3868"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12"/>
                                    </textElement>
                                    <text><![CDATA[Last Name]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="200" height="30" uuid="be9b6c0d-dc9b-43f0-b17d-1bf7a24af3e6">
                                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                                    </reportElement>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="11"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{Last Name}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="200" uuid="eb8ac0d4-1b63-46f9-84de-cd5d2e50aabb">
                            <property name="com.jaspersoft.studio.components.table.model.column.name"/>
                            <jr:columnHeader style="Table_CH" height="30">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <staticText>
                                    <reportElement x="0" y="0" width="200" height="30" uuid="db802f9a-9d3e-4a73-a8a8-23aa2c486ea7"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12"/>
                                    </textElement>
                                    <text><![CDATA[Organization Name]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                    <reportElement x="0" y="0" width="200" height="30" uuid="28e8791f-9fc7-41e9-b5d7-b0d6c3e640ec">
                                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                                    </reportElement>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="11"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{Organization Name}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                    </jr:table>
                </componentElement>
            </band>
        </detail>
        <lastPageFooter>
            <band height="50">
                <staticText>
                    <reportElement x="0" y="20" width="422" height="15" uuid="53446078-6906-48c0-a3b4-d538e542a3ff">
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                    </reportElement>
                    <text><![CDATA[Footer]]></text>
                </staticText>
            </band>
        </lastPageFooter>
    </jasperReport>
    

0 个答案:

没有答案