But in case no filter instance is passed in, 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 want to remove both page headers and page footers and also the group header of a group called ProductGroup, that comes from a subreport called ProductReport this 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:
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 our specific portions of that particular document, but they also work globally, if placed in the jasperreports.properties file (see Configuration Reference). This would allow removing the page headers and page footers from all reports, when exporting to XLS, for example.
All the above examples can be tested by putting the properties in the MasterReport.jrxml file of the /demo/samples/subreport sample provided with the project distribution package.
Starting in JasperReports Server 4.7.1, an addition was made to allow export filter propagated to sub report element. This is in response to a need for the export filter to work with Jive enabled report HTML output through report table elements introduced in 4.7.0 release of our product. This includes Ad Hoc-based reports since Ad Hoc uses table elements. User will need to add a wild card property setting to reference to the original filter in order to make the filter work in main and sub elements of a report. For example, to suppress column header band from the XLS export but to keep only its first occurrence, users need to code the following property:
net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.3=columnHeader net.sf.jasperreports.export.xls.exclude.origin.keep.first.report.3=* net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.4=columnHeader
In the snippet above the '3' entries apply the setting to all subreports and table elements, the '4' entry applys to columnHeader of main reports
For more information, please refer to Example on Suppressing Headers of Main and Sub Report Elements When Exporting to XLS