如何消除Jasper的CSV输出中的尾随逗号

时间:2017-02-20 10:45:01

标签: java csv jasper-reports

我的jasper数据源是JRBeanCollectionDataSource,输入是跟随集合。 [SampleData [SerialNo = 1,code = 123,price = 20],SampleData [SerialNo = 2,code = 234,price = 20]]。

代码段:

 <?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="custom" language="groovy" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2a3860b7-4c46-41ea-aae9-7f02e3679927">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="SerialNo" class="java.lang.String">
            <fieldDescription><![CDATA[SerialNo]]></fieldDescription>
        </field>
        <field name="code" class="java.lang.String">
            <fieldDescription><![CDATA[code]]></fieldDescription>
        </field>
        <field name="price" class="java.lang.Long">
            <fieldDescription><![CDATA[price]]></fieldDescription>
        </field>
        <title>
            <band height="22" splitType="Stretch">
                <staticText>
                    <reportElement x="0" y="0" width="22" height="20" uuid="5fc7b8ea-a635-4997-802e-82f3e06c8694"/>
                    <text><![CDATA[HDR]]></text>
                </staticText>
                <textField>
                    <reportElement x="22" y="0" width="130" height="20" uuid="f653a4ef-7863-4ea2-bb52-0cfa38d26ef0"/>
                    <textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="152" y="0" width="130" height="20" uuid="409ca2ad-ccf8-4007-bf41-ca67fee156fe"/>
                    <text><![CDATA[Rupees]]></text>
                </staticText>
            </band>
        </title>
        <detail>
            <band height="22" splitType="Stretch">
                <staticText>
                    <reportElement x="0" y="0" width="22" height="20" uuid="5fc7b8ea-a635-4997-802e-82f3e06c8694"/>
                    <text><![CDATA[BDY]]></text>
                </staticText>
                <textField>
                    <reportElement x="22" y="0" width="130" height="20" uuid="f653a4ef-7863-4ea2-bb52-0cfa38d26ef0"/>
                    <textFieldExpression><![CDATA[$F{SerialNo}!=null?$F{SerialNo}:"-"]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="152" y="0" width="130" height="20" uuid="ed37edb9-bb8f-43bf-904f-6ca5b5941aea"/>
                    <textFieldExpression><![CDATA[$F{code}!=null?$F{code}:"-"]]></textFieldExpression>
                </textField>
            </band>
        </detail>
        <summary>
            <band height="22" splitType="Stretch">
                <staticText>
                    <reportElement x="0" y="0" width="22" height="20" uuid="5fc7b8ea-a635-4997-802e-82f3e06c8694"/>
                    <text><![CDATA[TRL]]></text>
                </staticText>
                <textField>
                    <reportElement x="22" y="0" width="130" height="20" uuid="adcc7751-da03-4141-9045-821960ce77c7"/>
                    <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
                </textField>
            </band>
        </summary>
    </jasperReport>

它给出了如下输出。

HDR,20,Rupees
BDY,1,123
BDY,2,234
TRL,2,

但我不希望拖车部分有逗号。输出应如下。

HDR,20,Rupees
BDY,1,123
BDY,2,234
TRL,2

0 个答案:

没有答案