Column headers are recurring in the CSV or XLS export in Jasper Reports when using the "Table Element" - jasper-reports

The column headers are recurring when a csv or xls import is done in the jasper reports. This is if we are using a "Table Element" in the report. I have figured out the way to exclude the column headers if the Table element is not used . I have used the following lines properties to do so
`
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.2" value="pageFooter"/>
<property name="net.sf.jasperreports.export.csv.exclude.origin.keep.first.band.3" value="columnHeader"/>
<property name="net.sf.jasperreports.export.csv.exclude.origin.keep.first.report.3" value="*"/>
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.4" value="columnFooter"/>`
But the problem persists if I am using a Table element.
I have added the property to the table properties and tried but it seems to be not working.

For XLSx, To prevent the column headers to be recurring from table element, try setting the below three parameters and run the report.
net.sf.jasperreports.export.xlsx.exclude.origin.report.myreport=YOUR_REPORT_NAME
net.sf.jasperreports.export.xlsx.exclude.origin.keep.first.band.myreport=columnHeader
net.sf.jasperreports.export.xlsx.exclude.origin.keep.first.report.myreport=*
NOTE: replace the report name with actual value in the first property.

Related

Jasper report - getting duplicate records

We are exploring Jasper reports to replace our current reporting engine. Our data source will be REST APIs, and we'll be needing to join multiple tables. I came across the CData JDBC driver for REST, and it seemed apt for the purpose.
I have created a JDBC data adapter using the CData driver, with a JSON file as a source which has data for 2 entities - users and posts.
Then I created a report with this data adapter to display fields in a table. The data is a result of join query on both the entities as below -
SELECT users.name,users.username,users.email,users.website,posts.title FROM users join posts on users._id = posts.userId
Below is the data adapter configurations -
CDataDataAdapter.xml
<jdbcDataAdapter class="net.sf.jasperreports.data.jdbc.JdbcDataAdapterImpl">
<name>CDataDataAdapter</name>
<driver>cdata.jdbc.rest.RESTDriver</driver>
<username />
<password />
<savePassword>true</savePassword>
<url>jdbc:rest:Format="JSON";URI="D:/Documents/ToJasper/SampleJoinJson.json";XPath="/posts;/users";DataModel="Relational";JSONFormat="JSON";SSLServerCert="*";Logfile="D:\Documents\Tasks\ToJasper\cdata-driver.log";Verbosity="4";Location="D:\Documents\Tasks\ToJasper\Schema";FlattenObjects="False";GenerateSchemaFiles="OnStart";RowScanDepth="10";</url>
<database />
<serverAddress />
<classpath>I:\Program Files\CData\lib\cdata.jdbc.rest.jar</classpath>
<classpath>I:\Program Files\CData\lib\rssbus.jar</classpath>
</jdbcDataAdapter>
The data is fetched the rendered in the report, but the problem is it gets repeated.
The table is repeated in the report 5 times, 4 times with full data, and one time with only column headers. I cannot understand why, any help is greatly appreciated.
I got the answer here - https://community.jaspersoft.com/questions/904196/same-detail-shown-multiple-times-page-and-multiple-pagesireports-well-jaspersoft
I added the table component in the Detail band instead of Summary band. Quoting from the answer above -
"Where did you put the table and chart element in the report? They should be placed in SUMMARY section, not detail section. JR report detail band is called for each row fetched into report. If you have 100 rows, it will display information in the detail band 100 times each with details of that row. Tables and charts gather and tally all your data to display and should be placed in the summary band thus have them displayed only once."

Remove Column Headers in JasperReports jr:table component

I am using JasperReports (Jaspersoft Studio for designing templates) for a project that needs both PDF and Excel 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?
The output result:
The report's design:
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.

Jaspererports iReport: split report into several excel sheets on export

I have a report which I created using iReport designer. The report contains 3 datasets and 3 tables, which get filled with data from those datasets. Each table is located in detail band. Our business owner wants these 3 tables to be displayed on 3 different excel sheets upon excel export. I have checked several tutorials and posts, but none of them seems to work for me. Help needed! Thanks in advance!
add pagebreak after each table, then set property
net.sf.jasperreports.export.xls.one.page.per.sheet to true
like this
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="true"/>
for more reference visit this page

Dynamic Query in JasperReport

I am new to JasperReports and I am trying to build a "dynamic report".
In JasperREports ultimate guide it's said that we can pass table names and table columns names as parameters using $P!{paramName} Syntax:
<queryString>
<![CDATA[
SELECT * FROM $P!{MyTable} ORDER BY $P!{OrderByClause}
]]>
</queryString>
I have created different views of my table for different period aggregations.
Then I am trying to pass the view's name as a parameter so that I can choose which period to display in the report BUT with no success.
Can anybody help me?
In order to help you, we must know the error you are retrieving, how do you execute the report (within iReport? through a Servlet? using JasperServer?) Are these parameter instanciated? you can begin by outputing the query string, or the parameters themselves in the report, to see what sentence are you using to retrieve your dataset...

Records not displayed in Jasper reports properly

I have a XML Datasource in jasper reports.
And a sample xml is given below
<bill>
<data>Test1</data>
</bill>
<bill>
<data>Test2</data>
</bill>
<bill>
<data>Test3</data>
</bill>
Now when I generate Jasper report from Ireport or java program only
Test1 is printed.
I want to print
Test1
Test2
Test3
When you have multiple tags with similar name, you need to use a "List Component" so that jasper reports scrolls through all of them.
If you will use simple text box, only the first tag data will be displayed.
For using list component, you need to create a data set first.
Then use a list component with sub-dataset as the data set that you created.