Reputation: 499
I have to generate a simple csv file with JasperReports.
Which is the simplest jrxml file to do this?
I tried this:
<?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="report5a"
language="groovy">
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.Integer"/>
<field name="col3" class="java.lang.Integer"/>
<field name="col4" class="java.lang.String"/>
<detail>
<band height="16">
<textField>
<reportElement x="0" y="0" width="1000" height="15"/>
<textFieldExpression><![CDATA[$F{col1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="1000" y="0" width="1000" height="15"/>
<textFieldExpression><![CDATA[$F{col2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="2000" y="0" width="1000" height="15"/>
<textFieldExpression><![CDATA[$F{col3}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="3000" y="0" width="1000" height="15"/>
<textFieldExpression><![CDATA[$F{col4}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
It is working, but why should I have to provide width, or height parameters??? And if the x and width attributes are too low, then the values will be cut. For example, if all the of values (mentioned before) are divided by 1000, then the result will contains only 4 characters.
Ideas?
Thanks
Zsom
Upvotes: 0
Views: 5120
Reputation: 9390
JasperReports can certainly generate CSV files. But if that's your only goal, then there are much better choices than JR. It's vastly bigger than what you need.
To avoid having to set silly widths like you're doing now, you should set the property net.sf.jasperreports.print.keep.full.text.
EDIT: with that property set then your field widths can be any positive value. You don't need to worry about making them wide enough to accomodate the text without wrapping.
Upvotes: 3