开发者

Why do I get extra commas in csv export?

I have written same jrxml to export report in pdf and csv format. The pdf report is fine, but for csv report, it is inserting extra commas in a line.

Here is the example of csv report output:

TXN ID,,TXN TIME,,,AGENT,DP USER,USECASE,AMOUNT,,COMMN
10000799,,7/27/11 7:58 PM,,,Headquarter,Headquarter,Standard In,0 EUR,,0

As it can be seen, there are two commas after txn id and three commas after txn time.

Any idea how can i avoid having these extra commas?

Here is the part of XML

<staticText>
<reportElement key="element-91" x="0" y="27" width="60" height="16" forecolor="#FFFFFF"/>
<box leftPadding="2" rightPadding="2">
    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
    <font fontName="" size="12"/>
</textElement>
<text><![CDATA[TXN ID]]></text>
</staticText>
<staticText>
<reportElement key="element-90" x="60" y="27" width="65" height="16" forecolor="#FFFFFF"/>
<box leftPadding="2" rightPadding="开发者_如何学C2">
    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
    <font fontName="" size="12"/>
</textElement>
<text><![CDATA[TXN TIME]]></text>
</staticText>


This could have something to do with the graphical layout in the report. Between the TXN ID and the TXN TIME elements there may be some space horizontally in the report design, whereas the elements AGENT and DP USER may be next to each other, without a horizontal gap. The CSV exporter tries to create a layout similar to the report's design, at least when viewed in a spreadsheet application.


I had a similar problem and the issue turned out to be caused by the vertical misalignment of the fields in the designer view. The solution is to make sure that all your field elements start on the same vertical position/level (i.e. set the property "top" to be the same for all your fields, for example top=0) in the designer view.

  • midestar


Designing Reports for CSV Export: http://community.jaspersoft.com/wiki/designing-reports-csv-export

I have added the next tip: Check that "Print repeated values" is enabled

I hope that this could be usefull.


Found this while having the same type of issue, to give an idea of what my report looked like:

ColumnHeader [Field1, Field2, Field3]
Detail Band  [List]

Where my list was:

[field1|field2|field3]

And I was seeing the same type of issue:

  • CSV with no header looked great
  • CSV with header added extra commas between fields

After debugging I found that at line 232 of JRCsvExporter

if (xCuts.getCut(x).isCutNotEmpty())

was true, which is why there were extra commas. I'm not entirely sure where CutInfo(s) come from, and haven't spent any time debugging to figure it out; but they definitely play a huge role. I found you need to make sure all your columns in CSV are exact in size (not just in number).

After some painstaking manual movement I found that one Column 1 of my List was 1 pixel off the size of my column header Column 1. After manually ensuring that each column of the header matched the widths of the columns within the list, the report exported without the extra commas.


The solution is to set the parameter isIgnorePagination on the report level to true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜