The following are some tips for designing reports specifically for comma delimited (CSV) output. As well as some troubleshooting advice when experiencing certain unexpected results associated with CSV output.
- Set net.sf.jasperreports.print.keep.full.text to true
- Ensure that isStretchWithOverflow/Stretch with Overflow is false
Fields are Getting Cut Off and Records are breaking across lines
In some cases, when the data go beyond the size of the field display element, the values may be truncated. In addition, long fields may cause the text field display elements to stretch beyond the page size.
Cut Off Values Solution #1
Set net.sf.jasperreports.print.keep.full.text to true.
This can either be done globally by setting it in the jasperreports.properties file or it can be done on a single report by adding the following to the JRXML:
<?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="report name" pageWidth="280" pageHeight="100" columnWidth="240" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/>
Ensure that isStretchWithOverflow/Stretch with Overflow is false
In iReport, a text field has a property shown as Stretch with Overflow that when left unchecked will result in the textField element not having the isStretchWithOverflow set (false by default). The value can specifically be set on the textField element as shown below within the JRXML, although this is not necessary:
<textField isStretchWithOverflow="false" />
Ensure that all display elements are set with isStretchWithOverflowas false.
Cut Off Values Solution #2
Make sure that texts do not break across pages by setting a page height big enough to accommodate the longest text, and set isSplitAllowed="true" for the detail band.
Controlling the delimiter
The default delimiter when exporting a CSV file is the comma. This is reasonable, since "CSV" stands for comma separate values. But you may want to export files with tabs, semicolons, or other delimiting characters. This is easily configurable in JasperServer. For example, change "," to " " in applicationContext.xml here:
<bean id="csvExportParameters" class="com.jaspersoft.jasperserver.api.engine.jasperreports.common.CsvExportParametersBean"> <property name="fieldDelimiter" value=","/> </bean>