Java 如何消除Jasper CSV输出中的尾随逗号
我的jasper数据源是JRBeanCollectionDataSource,输入是以下集合。 [SampleData[SerialNo=1,code=123,price=20],SampleData[SerialNo=2,code=234,price=20]] 代码段:Java 如何消除Jasper CSV输出中的尾随逗号,java,csv,jasper-reports,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/ja
<?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卢比
BDY,1123
BDY,2234
TRL,2,
但我不想在预告片部分使用尾随逗号。输出应如下所示
HDR,20,Rupees
BDY,1,123
BDY,2,234
TRL,2
HDR,20卢比
BDY,1123
BDY,2234
TRL,2我认为JR无法帮助您解决此任务。您应该编写一些Java代码。顺便说一句,在逻辑中,
BDY、<123
行的正确结果是什么?如何导出此代码?我从输出中假设它可能是CSV,但您没有指定哪一个使正确建议变得困难。如果是这样的话,正如Alex K所说,它必须用Java脚本来处理,因为这不是Jasper的直接问题。