+ All Categories
Home > Documents > JasperReports

JasperReports

Date post: 30-Dec-2015
Category:
Upload: wynter-sears
View: 31 times
Download: 0 times
Share this document with a friend
Description:
JasperReports. Open Source Reporting Engine. JasperReports. Reporting Engine & Compiler Various Input Options – XML, Hibernate, JDBC, CSV… Various Output Options – PDF, Excel, HTML, RTF, TXT, XML Ability to create Charts http://jasperforge.org/sf/projects/jasperreports. iReport. - PowerPoint PPT Presentation
25
JasperReports Open Source Reporting Engine
Transcript
Page 1: JasperReports

JasperReports

Open Source Reporting Engine

Page 2: JasperReports

JasperReports

• Reporting Engine & Compiler

• Various Input Options – XML, Hibernate, JDBC, CSV…

• Various Output Options – PDF, Excel, HTML, RTF, TXT, XML

• Ability to create Charts

• http://jasperforge.org/sf/projects/jasperreports

Page 3: JasperReports

iReport

• Report GUI Design tool

• Built-In Compiler to create compiled reports

• http://www.jasperforge.org/sf/projects/ireport

Page 4: JasperReports

Requirements

• JRE 1.4 or higher

• Commons Beanutils• Commons Collections• Commons Logging • Commons Digester

• Itext – for PDF output• POI – for Microsoft formats

• JFreeChart – if using Charts/Graphs

Page 5: JasperReports

Ant Task

• Ant task is located in Tools that will compile reports

• Add to build.xml to enable Jasper compiling on build

Page 6: JasperReports

iReport/Making Report Definition

• Located in Tools

File Types:

• .jrxml – report definition (xml format)

• .jasper – compiled report definition

• iReport can open either version

Page 7: JasperReports

Basic Report Layout

• Each section of the report is called a band• Different bands will print different sections of the

report• Bands can be added, removed and resized• Not all bands are always used• Fields can be moved, stretched and resized

using the mouse.

Page 8: JasperReports

Types of Fields

• Static Text – non-data fields, i.e. Headings, titles, labels, etc.

• Text fields – can be data and/or non-data

• Variables – used for calculating of fields

• Parameters – passed into the report at compile time

Page 9: JasperReports

New Text Field

• View Fields• Click New• Enter the field name –

this will define it in the report

• Select Class Type – String is text fields, BigDecimal for amount fields

Page 10: JasperReports

<CompleteReceipt> <Receipt>

<number>0155</date> <date>255</date> <Item> <number>1</number>

<quantity>10</quantity>….

</Item> <Item>

….</Item>

</Receipt></CompleteReceipt>

Record Path is: /CompleteReceipt/Receipt/Item

Page 11: JasperReports

Field Description

• The field description field is the path to the data from the record path

• If we have a receipt, with items, it’s record path is: /CompleteReceipt/Receipt/Item

• To access the Receipt number, the field description would be: ../number (the .. will go up the tree)

• If a CompleteReceipt piece of data is needed, it would be: ../../data

Page 12: JasperReports

Adding a Variable

• View Variables, and click New.

• Enter a variable name.• Choose calculation type,

Add, multiply, etc.• Class type and

Expressions should be of BigDecimal type

Page 13: JasperReports

Adding a Parameter

• View Parameters, click New

• Enter name and select class type.

• These are passed into the report at compile time.

Page 14: JasperReports

Subreports

• A separate .jasper file that is used inside of another report.

• A data source can be applied to a subreport in the report properties as shown here:

Page 15: JasperReports

Subreports, cont.

• Parameters are defined on the Subreport (other) tab.

• The subreport Expression field will be the path to the subreport. We pass these in via a parameter.

Page 16: JasperReports

Compile Report

• Build Compile will build the report, and create a .jasper file. This file will be used in the java code.

• Ant task will also do this if added to build script.

Page 17: JasperReports

Back to Java Code

• Now, our .jasper files are created. Time to compile them with the data.

• Need the following imports (using XML data source and PDF output):

Page 18: JasperReports

Creating Final report

• First we need to get our jasper files, main report and any subreports:

• In USASWeb, we keep the paths to these files in StrutsResources.

Page 19: JasperReports

Creating Final report, cont.

• Now, we need to create an ArrayList for our report(s) and a Hashmap for any paramters.

• A parameter needs the parameter name, and then the data to send.

Page 20: JasperReports

Creating Final report, cont.

• Now, we can get our data. This shows an xml, being input thru a ByteArrayInput Stream.

• The Xml data source needs an input stream, and the record path. (can also take in a File, Document, JDBC connection)

Page 21: JasperReports

Creating Final report, cont.• Now, we fill the report. We need to pass

in the main reports path, our parameters and the data source.

• Then, we can add the report to our PrintList. (if using PDF bookmarks or to set the spreadsheet name in Excel, use the setName method)

Page 22: JasperReports

Creating Final report, cont.

• Now, we have our report made, now time to export it. I will show the PDF exporter.

• First, create a new PDFExporter instance, and get the response ready for our output.

Page 23: JasperReports

Finally, the report is done!

• Now, we set the exporter parameters. Here, we need our PrintList, output method, and since we are using PDF bookmarks, we need to set the flag.

• Finally, we export the report.

Page 24: JasperReports

Result• Now, it will be output to the browser.

Page 25: JasperReports

Questions?


Recommended