An exporter filter that excludes elements based on their origin.
In case no filter instance is passed to the exporter as the
ReportExportConfiguration.getExporterFilter()
exporter
configuration, the exporter searches for some
configuration properties with a given prefix, both at report level (exporter hints) and
globally, in order to decide if a default exporter filter instance should be created on-the-fly
and used internally, when exporting the current document.
If created, this default exporter filter will filter out content from the exported document
based on element origin information. Elements present in JasperReports generated
documents keep information about their origin. The origin of an element is defined by its
parent section in the initial report template, and optionally the name of the group and/or
subreport that the element originated from.
Removing page headers and page footers from the document when exporting to XLS can
be achieved by putting these custom properties in the report template:
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="pageHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter"/>
If you want to remove page headers and page footers, but keep the first page header in
place (useful when all pages are exported to the same sheet, in a flow layout) the
following properties have to be used in the report template:
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="pageHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter"/>
Note that there is no property prefix available to keep the last occurrence of a band. If
you would want to keep the last page footer, then the best solution is to actually use the
<lastPageFooter>
section of the report template.
If you want to remove both page headers and page footers and also the group footers of a
group called
ProductGroup
, that comes from a subreport called
ProductReport
these custom properties are needed:
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="pageHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.3" value="groupHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.group.3" value="ProductGroup"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.report.3" value="ProductReport"/>
Note that the number at the end of the properties names is just an arbitrary suffix. The
only thing that counts is that the suffix be the same for properties referring to the same
filter. The last three properties in the above example define the filter that will exclude
group header of ProductGroup from ProductReport subreport. Instead of the
numeric suffix, you could put any suffix, as long as it does not coincide with suffixes
from other filters. The following example will exclude the same group header while
keeping its first occurrence:
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.myGroupFilter" value="groupHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.group.myGroupFilter" value="ProductGroup"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.report.myGroupFilter" value="ProductReport"/>
The
xls
token inside the properties prefixes refer to the particular export format that is
targeted and the general syntax of the origin exporter filter properties is:
net.sf.jasperreports.export.{format}.exclude.origin.{suffix}.{arbitrary_name}
net.sf.jasperreports.export.{format}.exclude.origin.keep.first.{suffix}.{arbitrary_name}
Other supported format tokens are
pdf
,
html
,
rtf
,
odt
,
xml
,
txt
,
csv
and
graphics2d
, while the only accepted suffixes are
band
,
group
and
report
.
These properties make best sense when placed inside a report, to filter out specific
portions of that particular document, but they also work globally, if placed in the
jasperreports.properties
file. This would allow removing the page headers
and page footers from all reports, when exporting to XLS, for example.