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

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?

Related

How to remove space between list item in Jasper Report

jasper report result
I found that problem is with this PROPERTY_FRAMES_AS_NESTED_TABLES property. If I set it to true in JRHtmlExporter, then space disappears, but it also affects all reports in a very bad manner. So I tried to put it in jrxml file, but nothing changes.
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="...">
<property name="net.sf.jasperreports.export.html.frames.as.nested.tables" value="true"/>
UPDATE
I have a main report that contains a few subreports including my-list.jrxml that must have FRAMES_AS_NESTED_TABLES true, but the rest reports must remain false.
So I set htmlExporter.setParameter(JRHtmlExporterParameter.FRAMES_AS_NESTED_TABLES, Boolean.FALSE); (this is main report),
but in my-list.jrxml I wrote <property name="net.sf.jasperreports.export.html.frames.as.nested.tables" value="true"/>
And it doesn't work.
What surprise's me is that this property should default to true Jasper report API, so setting true will not change it!
Maybe your changed something else?, you have another problem!
Checkout also this property:
net.sf.jasperreports.export.html.remove.emtpy.space.between.rows
ps. the emtpy is a famous typo in jaser report!, its not mine ; ) ds.
EDIT: User found that he was setting false during export, so what ever he put in the property will be override during export.., so how can I set it true when I need, and the rest of the time false, without changing the other reports?
You can access the properties of JasperReport on the JasperReport object
So after compilation before you fill you can do something like this
String myProperty = jasperReport.getProperty("my.property");
if (myProperty!=null && myProperty.equals("specialValue")){
//What ever you like don't set it false for example ....
}
and now just set in jrxml.
<property name="my.property" value="specialValue"/>
when you want the if to execute

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.

JasperReports XLS export pagination and other issues

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.

How to create jrxml for sub reporting

I want create a complex jrxml file to create PDF.
I want to put another jrxml in my jrxml file.
So.. my question is how to put one jrxml to another jrxml
My jrxml files are: salesreport.jrxml, financialreport.jrxml and report.jrxml
I want to put salesreport.jrxml and financialreport.jrxml to report.jrxml.
Usually you develop reports with iReport.
iReport has facilities for including subreports within reports (by dragging the subreport icon onto the master report page).
Note that JasperReports uses absolute paths for file references. I would recommend you set up parameters to your reports as follows:
$P{ROOT_DIR}
$P{SUBREPORT_DIR}
Give $P{SUBREPORT_DIR} a default value of $P{ROOT_DIR} + "subreports/".
At that point, you can pass the absolute path as $P{ROOT_DIR} into your report and then the subreports will be stored in a subdirectory called subreports, which is located in $P{ROOT_DIR}.
Or use the JasperCompileManager class from within the master jrxml file to dynamically compile it.
<subreportExpression><![CDATA[JasperCompileManager.compileReport($P{SUBREPORT_DIR}+"/myFile.jrxml")]]></subreportExpression>