Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasper Reports : Same template for CSV and PDF Issue

I have a report where the export result in pdf and csv differ in some columns and I want to use the same template for both exports. CSV would have more or less columns compared to PDF output. Im using JRCsvMetadataExporter as my CSV exporter. So what I tried to do is create a separate band for CSV and PDF, In the band intended for CSV, my code was like

<band height="0">
  <printWhenExpression><![CDATA[Boolean.FALSE]]></printWhenExpression>
  <textField>
      <reportElement x="0" y="0" width="119" height="0">
            <property name="net.sf.jasperreports.export.csv.column.name" value="Column_1"/>
             <propertyExpression name="net.sf.jasperreports.export.csv.data"><![CDATA[$F{COL_1}]]></propertyExpression>
       </reportElement>
   </textField>
</band>

But when I ran the export, nothing was getting generated for CSV, I was expecting when printWhenExpression is false, it wont be included in the PDF export and CSV exporter will include columns mentioned in the band. Could anyone let me know what Im doing wrong here?

like image 786
Balaji Paulrajan Avatar asked Dec 03 '25 15:12

Balaji Paulrajan


1 Answers

If printWhenExpression is hard coded with Boolean.FALSE then it will never appear in PDF and CSV. Try to add the element with width and height as 0 in the jrxml which will make it not appear in the PDF but it will appear in the CSV since you are using the JRCsvMetadataExporter

like image 58
Cid Avatar answered Dec 06 '25 03:12

Cid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!