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

Jaspersoft Community 'Read-Only' as of July 8, 2022

Transition to New TIBCO Community Just Weeks Away

You can still search, review wiki content, and review discussions in read-only mode. Please email community@tibco.com with questions or issues requiring TIBCO review or response.

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 ?


 
 
andre.erasmus's picture
Joined: Mar 19 2013 - 2:33am
Last seen: 6 years 2 months ago

2 Answers:

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

Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 4 months 2 weeks ago

When I export to xls, it works, but not to CSV
I still want the headers there when viewed as PDF, so they should just be hidden when exporting to CSV

(I know this has to be possible because it works like this for my "export to xls")

andre.erasmus - 9 years 5 days ago

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

Attachments: 
AttachmentSize
Binary Data samplerun.jrxml7.12 KB
PDF icon PDF Export7.61 KB
File CSV Export3.57 KB
Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 4 months 2 weeks ago

Thx man, This will definitely work, was just looking for a way to do this in the jasper code, as there is about 400 reports this will have to be added to

andre.erasmus - 9 years 4 days ago

You are welcome
Cheers!!

Ankur Gupta - 9 years 4 days ago

Brilliant solution, Ankur. Thank you.

Too bad it's so difficult to implement such an obvious thing.

Jay

jay_2 - 7 years 4 months ago
Feedback
randomness