Jump to content
We've recently updated our Privacy Statement, available here ×

How do I Export to CSV Without Header & Footer repeating ?


andre.erasmus

Recommended Posts

I want to export to CSV with the Header and Footer only showing once

The current output
:
Name   Address Hobby
AAA    US      XXXXX
BBB    UK      XXXXX
(Footer)
Name   Address Hobby
CCC    ID      XXXXX
DDD    CC      XXXXX
(Footer)
Name   Address Hobby
EEE    SA      XXXXX
FFF    ZM      XXXXX
(Footer)
 
The desired output:
Name   Address Hobby
AAA    US      XXXXX
BBB    UK      XXXXX
CCC    ID      XXXXX
DDD    CC      XXXXX
EEE    SA      XXXXX
FFF    ZM      XXXXX
(Footer)
 
So how do I get the Header and footer to only show once ?


 
 
Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

This could be done by using the print when expression for tghe page header band as $V{PAGE_NUMBER} ==  1
This will solve the purpose for the page header

 

For the page footer for the last page you can simply use the band name LAST PAGE FOOTER

 

Hope that this helps

 

Thanks,

Ankur Gupta

Link to comment
Share on other sites

Hi,

If you are following the way I described it will work fine for csv .

Now if you want to vary the layout of header and footers then you could simply add a parameter suppose $P{OUTPUT_FORMAT} which takes user input to decide the layout the choices which user could enter would be "CSV","PDF","XLS" .. etc. according to you needs. 

Suppose you have that parameter $P{OUTPUT_FORMAT} -I am here explaning in "CSV" and "PDF"

CASE 1:

When user enters CSV

The print when expression for report header would be       $P{OUTPUT_FORMAT} == "CSV" && $V{PAGE_NUMBER}==1

Now this will give you the header for the report only on the first page in the case of CSV Format

 

CASE 2:

When user enters PDF

The print when expression for report header would e $P{OUTPUT_FORMAT} == "PDF" 

 

Now to provide dynamism you can combine the PrintWhenExpressions like

 $P{OUTPUT_FORMAT} == "PDF" || ($P{OUTPUT_FORMAT} == "CSV" && $V{PAGE_NUMBER}==1)

 

Now here I have combined for PDF and CSV but you can do this in any other format

 

I have depicted the same in a sample JRXML it uses the sample database.And also attaching the CSV and PDF Exports.

 

Hope that it helps.

 

Thanks,
Ankur Gupta

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...