CSV formatting in Jasper Reports

穿精又带淫゛_ 提交于 2019-12-12 02:09:35

问题


I am exporting a report I created to a CSV file. The export goes fine but the formatting is off and the variable that I have displaying in a text field doesn't show up at all.

The formatting isn't aligning columns properly and it's re-sizing them so that the values don't show up unless you expand the column. Also, the text field displaying my variable $V{reportTotal} is set as a BigDecimal and formatted for currency. This text field doesn't show anything.

Everything looks great when I choose PDF output. What can I do to fix these formatting problems for CSV output?


回答1:


You can try this sample:

<jasperReport ...>
        ...
    <field name="ORDERS_ORDERID" class="java.lang.Integer"/>
    <field name="ORDERS_CUSTOMERID" class="java.lang.String"/>
    <field name="ORDERS_FREIGHT" class="java.math.BigDecimal"/>
        ...
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{ORDERS_FREIGHT}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="100" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{ORDERS_ORDERID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="200" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{ORDERS_CUSTOMERID}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

The result is:

32.38,10248,VINET
11.61,10249,TOMSP
65.83,10250,HANAR
41.34,10251,VICTE
51.3,10252,SUPRD
55.09,10260,OTTIK
3.05,10261,QUEDE
48.29,10262,RATTC

I think you should check your result csv file in basic text viewer/editor (for example, Notepad++ or Notepad on Windows).



来源:https://stackoverflow.com/questions/8157796/csv-formatting-in-jasper-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!