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

2

6

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 ?

EDIT:

Footer looks like

Version : 1.0.0
AcademicProgramBusinessEntityCentreDoma Execution Time : 00:00:00.00
/NWU/StudentInformation/AcademicProgramDevelopment Build: v1.0.9 - Dev

Gipps answered 2/7, 2013 at 12:51 Comment(9)
Can you post the jrxml file? About what Footer are you talking?Privatdocent
Edited the post so you can see footer, And I'm making changes to the Jasper code not jrxml's else I will have to change ALL the jrxml'sGipps
Is it Group Footer or Column Footer or Page Footer? And I'm making changes to the Jasper code - Are you talking about Java code? Are you using jrxml files or you are generate report dynamically with help of Java code?Privatdocent
its a page footer & page header that I only want at Top & bottom, & Yes, I am making changes to the Java code & the reports are saved in jrxml files (when I export to Excel the export works the way I want, but no luck with CSV)Gipps
If you have a jrxml - you should post it, if you have the Java code - you should post itPrivatdocent
Did you check the csv in basic text editor (in Notepad, for example)? Did you see the repeating data from footer there?Privatdocent
I'm not going to post Thousands upon Thousands of lines of code, most of the classes need the whole jasper install of function, anyone that has the Clean Jasper code (or modified) already has the code & It won't make a difference to open it in Notepad ?, Just opened it in Notepad, looks exactly the sameGipps
May be this help you: removing group while doing CSV export in JasperReports 4.0.5 & JasperReports: hide textfield when not HTML view.Privatdocent
Thx Alex, 1st link is what i want :D !! but I need to exclude page header & footer not Group header & footer , any idea how to do this ?Gipps
P
7

You can use net.sf.jasperreports.export.{format}.exclude.origin.{suffix}.{arbitrary_name}(see the http://jasperreports.sourceforge.net/config.reference.html page for details) property for excluding bands (Page Header and Page Footer in your case) for exporter.

The sample:

The input data, csv file (datasource):

AAA,US,XXXXX
BBB,UK,XXXXX
CCC,ID,XXXXX
DDD,CC,XXXXX
EEE,SA,XXXXX
FFF,ZM,XXXXX

The jrxml file:

<?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="exclude_band_for_csv" language="groovy" pageWidth="595" pageHeight="120" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="0" bottomMargin="0" uuid="daaa60dc-b91b-4e9b-bbc0-6189af985ef9">
    <property name="net.sf.jasperreports.export.csv.exclude.origin.band.1" value="pageHeader"/>
    <property name="net.sf.jasperreports.export.csv.exclude.origin.band.2" value="pageFooter"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="Name" class="java.lang.String"/>
    <field name="Address" class="java.lang.String"/>
    <field name="Hobby" class="java.lang.String"/>
    <pageHeader>
        <band height="35" splitType="Stretch">
            <staticText>
                <reportElement uuid="9da294e6-b5b7-489f-9469-7edb539315da" x="117" y="0" width="380" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <text><![CDATA[Page Header]]></text>
            </staticText>
        </band>
    </pageHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement uuid="6a615d39-86f1-4a74-8ae7-4f8ca8e19afe" x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="df0929d2-34c0-4561-ab98-e6e5ce37fd11" x="100" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{Address}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="675381d8-57b3-427f-88e4-ec4725ea3462" x="200" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{Hobby}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="45" splitType="Stretch">
            <staticText>
                <reportElement uuid="9da294e6-b5b7-489f-9469-7edb539315da" x="127" y="10" width="380" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <text><![CDATA[Page Footer]]></text>
            </staticText>
        </band>
    </pageFooter>
</jasperReport>

The report's design in iReport:

Report's design in iReport

The result of JRPdfExporter will be:

The result of generating the report in *PDF* format

Both bands are present in PDF file

The result of JRCsvExporter will be (the output csv file):

AAA,US,XXXXX
BBB,UK,XXXXX
CCC,ID,XXXXX
DDD,CC,XXXXX
EEE,SA,XXXXX
FFF,ZM,XXXXX

Both bands are absent in CSV file.

As you can see I've excluded two bands (Page Header and Page Footer) only for JRCsvExporter.


For more details you can also see this post: JasperReports: hide textfield when not HTML view

Privatdocent answered 3/7, 2013 at 8:34 Comment(0)
C
3

to prevent column header repeating you can use following property:

net.sf.jasperreports.export.{format}.exclude.origin.keep.first.{suffix}.{arbitrary_name}

for example to avoid column header repeating in csv you write:

<property name="net.sf.jasperreports.export.csv.exclude.origin.keep.first.band.1" value="columnHeader"/>

https://community.jaspersoft.com/wiki/how-can-i-suppress-page-headers-and-footers-when-exporting-xls

Culture answered 23/12, 2014 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.