为什么我在 csv 导出时会出现多余的逗号?

发布于 2024-11-28 05:18:27 字数 1723 浏览 1 评论 0原文

我编写了相同的 jrxml 以 pdf 和 csv 格式导出报告。 pdf 报告很好,但对于 csv 报告,它会在一行中插入额外的逗号。

下面是 csv 报告输出的示例:

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

可以看到,txn id 后面有两个逗号,txn time 后面有三个逗号。

知道如何避免这些多余的逗号吗?

这是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="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 TIME]]></text>
</staticText>

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="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 TIME]]></text>
</staticText>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

终止放荡 2024-12-05 05:18:27

这可能与报告中的图形布局有关。在报告设计中,TXN ID 和 TXN TIME 元素之间可能存在一些水平空间,而元素 AGENT 和 DP USER 可能彼此相邻,没有水平间隙。 CSV 导出器尝试创建与报表设计类似的布局,至少在电子表格应用程序中查看时是如此。

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.

夜巴黎 2024-12-05 05:18:27

我遇到了类似的问题,结果证明该问题是由设计器视图中字段的垂直未对齐引起的。解决方案是确保所有字段元素在设计器视图中从相同的垂直位置/级别开始(即将所有字段的属性“top”设置为相同,例如 top=0)。

  • 米德斯塔

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
旧故 2024-12-05 05:18:27

设计 CSV 导出报告:
http://community.jaspersoft.com/wiki/designing-reports-csv-export

我添加了下一个提示:
检查“打印重复值”是否已启用

我希望这会有用。

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.

我一直都在从未离去 2024-12-05 05:18:27

在遇到相同类型的问题时发现了这一点,以了解我的报告的外观:

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

我的列表在哪里:

[field1|field2|field3]

我看到了相同类型的问题:

  • 没有标题的 CSV 看起来很棒
  • 带有标题的 CSV 在字段之间添加了额外的逗号

经过调试我发现JRCsvExporter的第232行

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

是true,这就是为什么有多余的逗号。我不完全确定 CutInfo(s) 来自哪里,也没有花任何时间调试来弄清楚;但它们确实发挥着巨大的作用。我发现您需要确保 CSV 中的所有列的大小都准确(而不仅仅是数量)。

经过一番艰苦的手动移动后,我发现列表的第 1 列与列标题第 1 列的大小相差 1 个像素。在手动确保标题的每一列与列表中的列的宽度匹配后,导出的报告没有多余的逗号。

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.

苯莒 2024-12-05 05:18:27

解决方案是将报表级别的参数 isIgnorePagination 设置为 true

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文