JasperReports XLS export pagination and other issues - jasper-reports

I'm having trouble with JasperReports 4.0.2 XLS export. The file comes out but it seems to have certain issues each time, no matter which configuration I try:
Column headers will disappear unless I disable graphics e.g. vertical line separating the headers and the data.
I cannot remove repeating page and column headers and have all the data as a single details block. The page numbers cannot be removed also.
The same template is used for PDF export (which should have pages) and XLS export (which should be without pages). For achieving the desired XLS export I've tried configuring the export with JRXlsExporter parameters in the java code as well as changing properties in the default.jasperreports.properties file.
This far I haven't found any actual documentation on the topic. Few forums posts in the JasperReports site seem not to be working.
The Problem is solved.
Somehow JasperReports ignored the properties set in the java code during the export process with JRXlsExporter class and the properties file. However, the same delcarations did work then added directly to the JRXML file. The working code to remove repeating headers is below:
<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.keep.first.band.2" value="columnHeader"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/>
The titles did disappear due to separator line being drawn on top of the titles themself. PDF could handle this but XLS did not. By adding a few pixels of space in between the titles and the separator the problem did solve.

Related

How to disable options as printing in generated PDF file?

When I generate a PDF with jasper reports I don't want the user to be able to print it.
Is there some option to make it from the code or does it only depend on the program which visualize it (web browser,adobe etc.).
You can achive this both by using jrxml properties or setting values to the SimplePdfExporterConfiguration if you are exporting from java.
To protected your pdf document (hence in this case disallow printing), first thing you need to do is to encrypt it and be sure that you have nessary libraries for encryption in classpath see How to configure PDF encryption in JasperReports Server 5.6.1
jrxml properties
<property name="net.sf.jasperreports.export.pdf.encrypted" value="true"/>
<property name="net.sf.jasperreports.export.pdf.128.bit.key" value="true"/>
<property name="net.sf.jasperreports.export.pdf.owner.password" value="12345"/>
or
java code
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setEncrypted(true);
configuration.set128BitKey(true);
configuration.setOwnerPassword("1234");
Note we are setting owner password not user password, hence user will be allowed to open without.
Now set the user permissions
net.sf.jasperreports.export.pdf.permissions.allowed
In your case I guess you only like to allow screen readers, if you like to also allow COPY or other actions (see link above) add these with | to your properties
jrxml property
<property name="net.sf.jasperreports.export.pdf.permissions.allowed" value="SCREENREADERS"/>
or
java code
configuration.setPermissions(PdfWriter.ALLOW_SCREENREADERS);
Notice: it is up to the reader/application to respect the permission, hence a developer can always open and do what they want with any PDF document. As example iText contains a flag unethicalreading, if you set it to true, you will be able to have owner access to these documents without knowing the password.

jasperreports: how to include chart in xlsx (Excel) report?

At the moment, when I export report to XLSX (MS Excel) format, there is a white void at the top of the spreadsheet preceding the data - I guess, it is supposed to be the chart :). The report is also exported as HTML, PDF and JSON, all three without any visible issue.
I'm using JasperReport "community" edition. Here are the relevant lines from my build.gradle:
implementation group: 'net.sf.jasperreports', name: 'jasperreports', version: "6.6.0"
implementation group: 'net.sf.jasperreports', name: 'jasperreports-fonts', version: '6.0.0'
I found a few posts suggesting to set the property net.sf.jasperreports.export.xls.ignore.graphics to false.
OK, did that in the report template:
<jasperReport ..>
<property name="net.sf.jasperreports.export.xls.ignore.graphics" value="false"/>
Still a white hole instead of a chart.
Is there a solution to this issue, or do I just have to live with it?

Export xls.sheet into a groups of pages, iReport java

I wan't to export a Jasper Report to Pdf & Excel.
When the export type is PDF : i need the pagination of document to
be ignored.
When the type id EXcel : i need even page on an excel sheet and rename these sheet's by the label of the un-repeated group.
To print the whole document in a single page, your report must ignore pagination by default. For this, you've to check ignore pagination to true.
Your_Report >> Properties >> ignore pagination = true
For excel sheet's, add the following variable in a field that changes for each group, it makes it possible to do the jump for a new sheet.
<property name="net.sf.jasperreports.export.xls.break.after.row" value="true"/>
For change the name of the sheet dynamically on excel, you can use :
<propertyExpression name="net.sf.jasperreports.export.xls.sheet.name"><![CDATA[$F{libUniteOrg}]]></propertyExpression>

Exclude of bands lead to excess whitespace

Context
Setup: JasperReports server Product Version: 6.0.1 Build: 20141218_0238, CentOS server. I am using their bundled PostgreSQL + tomcat server setup.
In my report i have a table with text field and static field & and a chart in the summary band.
the static fields are in columnHeader band, and text fields are in the detail band.
I require the table because i want the users to be able to export CSV data.
However when the report is viewed as HTML, i want to exclude the two bands mentioned above (detail/columnHeader).
Problem
I am able to exclude the table so that it's not showed using the following:
net.sf.jasperreports.export.html.exclude.origin.band.1=detail
net.sf.jasperreports.export.html.exclude.origin.band.2=columnHeader
This does hide the two bands mentioned above, however now instead of the data - whitespace is shown, i would to know how i can remove it
The red text above was added by me, as you can see there are unwanted white-space between the title and the chart, that was where the columnHeader and detail band were at.
See the JRXML content.
Question
How can I remove the space?
It could be an issue with your styles or theme. I run the report in Jasper studio and there was no white space, but I created dummy styles (table_heading, table_data) and set the default theme for bar chart.
Here is my report
http://pastebin.com/fnAnvBR1
I'm using JasperStudio 5.6.2
Set the following property to true:
net.sf.jasperreports.export.html.remove.empty.space.between.rows
Earlier versions of JasperReports had a typo, for the property (emtpy instead of empty):
net.sf.jasperreports.export.html.remove.emtpy.space.between.rows
For example:
<property name="net.sf.jasperreports.export.html.remove.emtpy.space.between.rows" value="true"/>
<property name="net.sf.jasperreports.export.html.remove.empty.space.between.rows" value="true"/>

JasperReports CSV export

I am using iReport 2.0.2. I want to suppress page headers and footers while exporting to CSV alone but not in any other format. Can anyone please let me know how to do that?
You should use the net.sf.jasperreports.export.{format}.exclude.origin.{suffix}.{arbitrary_name} report's property.
The snippet of jrxml file for excluding pageHeader and pageFooter bands from the resulting csv file:
<jasperReport ...>
<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"/>
These properties only affect the csv exporter in this sample. For example, the pdf document will be with two bands (page header and footer).
It works for iReport 4.x. I did not check it for 2.x version.
The additional info available in How can I suppress page headers and footers when exporting to XLS? topic of FAQ at http://community.jaspersoft.com.