1 / 25

JasperReports

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.

Download Presentation

JasperReports

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JasperReports Open Source Reporting Engine

  2. 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

  3. iReport • Report GUI Design tool • Built-In Compiler to create compiled reports • http://www.jasperforge.org/sf/projects/ireport

  4. 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

  5. Ant Task • Ant task is located in Tools that will compile reports • Add to build.xml to enable Jasper compiling on build

  6. iReport/Making Report Definition • Located in Tools File Types: • .jrxml – report definition (xml format) • .jasper – compiled report definition • iReport can open either version

  7. 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.

  8. 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

  9. 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

  10. <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

  11. 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

  12. 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

  13. Adding a Parameter • View  Parameters, click New • Enter name and select class type. • These are passed into the report at compile time.

  14. 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:

  15. 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.

  16. 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.

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

  18. 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.

  19. 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.

  20. 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)

  21. 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)

  22. 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.

  23. 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.

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

  25. Questions?

More Related