Search code examples
jasper-reportsexport-to-csv

Exclude column header (but keep first) from a Table component on CSV export in Jasper Reports


I know how to exclude column header from a JR report on CSV report.

I need to know how to exclude column header (but keep first) from a Table component on CSV report.

If this is not possible, any suggestion other than ignore pagination is highly appreciated.


Solution

  • One possible solution is to add a key to each of the column Header report Element. (In this case, key="col_header" in the reportElement tag.)

    <jr:columnHeader style="table_CH" height="50" rowSpan="1">
        <staticText>
            <reportElement uuid="0c6dfd58-9df2-4e00-b79e-43a457c7b42e" key="col_header" x="0" y="0" width="90" height="50"/>
                 <textElement textAlignment="Center" verticalAlignment="Middle">
                  <font size="12"/>
             </textElement>
                 <text><![CDATA[ColumnName]]></text>
        </staticText>
    </jr:columnHeader>
    

    Next, exclude the key when exporting to CSV. (Add this property to the report properties list).

    <property name="net.sf.jasperreports.export.csv.exclude.key.col_header"/>
    

    Voila, the column headers are removed in CSV export.

    The downside of this approach:

    • It removes all the column Headers. (net.sf.jasperreports.export.csv.exclude.key.keep.first.col_header does not work).

    • Adding Key to each column Header is quite laborious.