Slide 1 - SSDT Public Wiki

streakconvertingΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

74 εμφανίσεις

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


Report GUI Design tool


Built
-
In Compiler to create compiled reports



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

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

Ant Task


Ant task is located in
Tools that will compile
reports


Add to build.xml to
enable Jasper
compiling on build

iReport/Making Report Definition


Located in Tools

File Types:


.jrxml


report definition (xml format)


.jasper


compiled report definition



iReport can open either version

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.

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

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


<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

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

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

Adding a Parameter


View


Parameters,
click New


Enter name and
select class type.


These are passed
into the report at
compile time.

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:

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.


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.

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):

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.

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.

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)

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)


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.

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.

Result


Now, it will be output to the browser.

Questions?