官术网_书友最值得收藏!

The features of JasperReports

JasperReports is capable of generating professional reports that include images, charts, and graphs, in addition to textual data. Some of the major JasperReports features include:

  • Flexible report layout
  • Multiple ways to present data
  • Multiple ways to supply data
  • Capability of accepting data from multiple datasources
  • Capability of generating watermarks
  • Capability of generating subreports

It is also capable of exporting reports in a variety of formats. Each of these features is briefly described in the next few sections.

Flexible report layout

JasperReports allows us to separate data into optional report sections. These sections include:

  • The report title, which will appear once at the top of the report
  • A page header, which will appear at the top of every page
  • A detail section, which typically contains the primary report data
  • A page footer, which will appear at the bottom of every page
  • A summary section, which will appear at the end of the report

All of these and other report sections are discussed in detail in Chapter 6, Report Layout and Design.

In addition to allowing us to define report sections, JasperReports allows the creation of elaborate dynamic layouts based on the contents of the report. For example, data can be hidden or displayed in a report, or it can even be grouped into logical sections, depending on the values of the respective report fields. Let's suppose that we are creating a report about cars. JasperReports allows us to group the data by make, model, year, or a combination of these or any other piece of data displayed on the report. Data grouping lets us control the layout of the report better. Data group definitions can also be used to calculate subtotal values based on a subset of the report data. Groups are also used to define datasets for charts and graphs. Data grouping is discussed in detail in Chapter 6, Report Layout and Design.

Multiple ways to present data

JasperReports provides the ability to display report data textually or graphically using charts. JasperReports allows us to use report expressions for generating reports that display dynamic data, that is, data that is not directly passed to the report or stored anywhere; instead, it is calculated from the data contained in the datasource and/or report parameters.

Multiple ways to supply data

JasperReports allows developers to pass data to a report through the report parameters. Report parameters can be instances of any Java class.

Data can also be passed to a report by using special classes called datasources. Report parameters and datasources can be combined for maximum flexibility.

Multiple datasources

JasperReports can generate reports using any relational database system supported by JDBC, but it is not limited to database reports. It can generate reports from a number of datasources including XML files, Plain Old Java Objects (POJOs), any class implementing the java.util.Map interface, and any class implementing the javax.swing.table.TableModel interface.

JasperReports also supports empty datasources, which are used for simple reports that have no dynamic data displayed. If we need to create a report from a datasource that is not directly supported by JasperReports, it also allows us to create our own custom datasources. JDBC datasources are discussed in detail in Chapter 4, Creating Dynamic Reports from Databases; other datasource types, including custom datasources, are discussed in detail in Chapter 5, Working with Other Datasources.

Watermarks

JasperReports is capable of generating background images or text on the reports it generates. These background images can serve as watermarks for the report. Watermarks can be used for branding reports and for security purposes, as they make it difficult to forge reports. As all report pages have the same watermark, reports can maintain a consistent look and feel.

Subreports

Another feature of JasperReports is its ability to create subreports, or reports within reports. Subreports simplify report design significantly by allowing us to extract complex report sections into a separate report and then incorporating that separate report into a master report.

Exporting capabilities

Reports generated with JasperReports can be exported to a number of formats, including PDF, Excel (XLS), and Rich Text Format (RTF). RTF is a format readable and editable by most word processors, such as Microsoft Word, OpenOffice.org Writer, StarOffice Writer, and WordPerfect. Reports created with JasperReports can also be exported to HTML, XML, CSV, plain text, and OpenDocument Format (ODF), the native file format of OpenOffice.org Writer. Exporting reports to these formats is discussed in detail in Chapter 9, Exporting to Other Formats.

The following screenshot demonstrates some of JasperReports' features, including data grouping, adding images and watermarks to a report, and exporting to PDF:

Exporting capabilities

When creating this report, we took advantage of JasperReports' data grouping capabilities to create groups dividing the data by country, state, and city. This grouping allowed us to display the data in a logical, easy-to-follow way. We also took advantage of JasperReports' ability to display images, to add a watermark and a logo in the report heading. The report font in the header section was enlarged and made bold, and the text was laid out in an easy-to-follow format.

In the previous screenshot, the freely available Evince document viewer was used to display the PDF report. Of course, reports exported to PDF can be viewed with any PDF viewer, including Adobe Acrobat, Foxit, and Xpdf.

主站蜘蛛池模板: SHOW| 清镇市| 长寿区| 隆化县| 长岭县| 台南市| 英吉沙县| 凤庆县| 嘉祥县| 光泽县| 塔城市| 六枝特区| 宁海县| 玉树县| 莱阳市| 台东县| 綦江县| 军事| 凤冈县| 洛浦县| 呼伦贝尔市| 珲春市| 湘潭县| 锦州市| 济源市| 定州市| 济源市| 新化县| 谢通门县| 邹城市| 铜梁县| 苍山县| 璧山县| 社旗县| 泌阳县| 安徽省| 孝义市| 正宁县| 台中市| 江达县| 社旗县|