简体   繁体   中英

Jasper Reports Exclude Column Headers in a Table?

I am using Jasper reports for a project that needs both PDF and CSV output and the majority of the data is the Detail section, within a table. I know you can remove the pageHeader and columnHeader at the document level, but is it possible to remove, or only print once, the column headers within a table? If not the CSV outputs,

User Type,Time,Username,Event,IP Address,Student Name,Student Number
Admin,6/6/11 8:09 PM,admin,Uploaded a report file.,0:0:0:0:0:0:0:1,,
 ....[about 20 more lines of CSV then]....
User Type,Time,Username,Event,IP Address,Student Name,Student Number

This just looks very unprofessional and isn't very functional. Like I said I know the page level headers can be removed with:

        jasperPrint.getPropertiesMap().setProperty("net.sf.jasperreports.export.exclude.origin.band.1", "pageHeader");
        jasperPrint.getPropertiesMap().setProperty("net.sf.jasperreports.export.exclude.origin.band.2", "pageFooter");
        jasperPrint.getPropertiesMap().setProperty("net.sf.jasperreports.export.csv.exclude.origin.band.1", "columnHeader");
        jasperPrint.getPropertiesMap().setProperty("net.sf.jasperreports.export.csv.exclude.origin.band.2", "pageFooter");
        jasperPrint.getPropertiesMap().setProperty("net.sf.jasperreports.export.csv.exclude.origin.keep.first.band.1", "columnHeader");

but I am looking for a solution to remove them on table for CSV output only, not PDF. Is this possible?

Any help would be greatly appreciated!

Thanks, Chuck

Some useful properties to control report export for different formats.

net.sf.jasperreports.export.xls.exclude.origin.band.1=title net.sf.jasperreports.export.xls.exclude.origin.band.2=summary net.sf.jasperreports.export.xls.exclude.origin.band.3=pageHeader net.sf.jasperreports.export.xls.exclude.origin.band.4=pageFooter net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1=columnHeader net.sf.jasperreports.export.xls.collapse.row.span=false net.sf.jasperreports.export.xls.remove.empty.space.between.columns=true

net.sf.jasperreports.export.csv.exclude.origin.band.csvSummary=summary net.sf.jasperreports.export.csv.exclude.origin.band.1=title net.sf.jasperreports.export.csv.exclude.origin.band.2=pageFooter net.sf.jasperreports.export.csv.exclude.origin.keep.first.band.1=columnHeader

net.sf.jasperreports.export.xls.exclude.origin.band.1=title net.sf.jasperreports.export.xls.exclude.origin.band.2=summary net.sf.jasperreports.export.xls.exclude.origin.band.3=pageHeader net.sf.jasperreports.export.xls.exclude.origin.band.4=pageFooter net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1=columnHeader net.sf.jasperreports.export.xls.collapse.row.span=false net.sf.jasperreports.export.xls.remove.empty.space.between.columns=true

net.sf.jasperreports.export.html.using.images.to.align=false net.sf.jasperreports.export.html.remove.emtpy.space.between.rows=true

net.sf.jasperreports.export.ignore.page.margins=true

Full reference .

Column headers in the table component are meant to be repeated when the table overflows and cannot be hidden. To achieve what you want you could either:

move the contents of your columnHeader into the tableHeader so that only the table header prints once or filter out the elements when performing a specific export by adding sets of properties like these:

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

More info on filtering elements at export time here and here .

Maybe you should use different report definitions for each output. If not, then you could just recognise when you're printing to csv and only set those properties then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM