Showing posts with label reporting frameworks. Show all posts
Showing posts with label reporting frameworks. Show all posts

Jan 18, 2010

Java Reports - Comparitive Study

One of the important goals that applications must be designed for is to be able to convey complex data to the end-user in the simplest, attractive and most understandable form and ‘Reports and Charts’ go a long way in achieving this goal. Java and JEE applications being one of the leaders in the enterprise application space commonly require to display complex data in the form of Charts (such as Pie charts, bar charts etc), Documents (PDF, MS Excel etc) or Reports that are customized specifically for an application . There are a number of tools available to the Java developer that can be utilized to generate reports. This document covers some of the important aspects of the most commonly used, freely available and Open-Source Reporting tools used in the Java world.

The Contestants:

This article covers three of the commonly used Reporting tools in Java application viz. Jasper Reports , DataVision and BIRT(Business Intelligence and Reporting Tools). All three are a favorite among Java applications primarily because of the following 3 reasons –

  • Freely available.
  • Open Source.
  • Good documentation and option to avail commercial support.
Jasper Reports

JasperReports is a powerful open source Java reporting tool that has the ability to deliver rich content onto the screen, to the printer or into PDF, HTML, XLS, CSV and XML files. It is entirely written in Java and can be used in a variety of Java enabled applications, including J2EE or Web applications, to generate dynamic content. Its main purpose is to help creating page oriented, ready to print documents in a simple and flexible manner.

Features

  • Wide array of output formats
  • Flexible Data Sources : JasperReports can use any data source provider, allowing it to extend reporting capabilities to almost any third-party application. When it is not possible to access data through JDBC, or when you do not want JasperReports to interact directly with a database, you can implement a custom JasperReports Data Source. The jasper reports can fetch data from the following different data sources:
    • Database JDBC connection
    • XML file data source
    • JavaBeans set data source
    • Custom JRDataSource
    • File CSV data source
    • JRDataSourceProvider
    • Hibernate connection
    • Spring loaded Hibernate connection
    • EJBQL connection
    • Mondrian OLAP connection
    • Query Executor mode
    • Empty data source
    • Custom iReport connection
    • XMLA Server Connection
  • Internationalized and Localizable
  • Conditional printing
  • Visual text rotation
  • Integrated barcode support
  • Web-based and pixel-perfect reports

Output formats

  • PDF, HTML, XLS, CSV and XML files
  • Can create custom reports by designing the UI ourselves and feeding data to the report-design.

Completely developed in Java and compatible with any Java application

Positives

  • Has iReport as an accompanying GUI tool to design reports.
  • When it is not possible to access data through JDBC, or when you do not want JasperReports to interact directly with a database, you can implement a custom JasperReports Data Source. In addition, any report can use data from multiple data sources, which can even be of different types.
  • Widely used for reporting in Java applications.
  • Hibernate query support in addition to SQL queries

Negatives

  • Extra compilation of the report-design every time.
  • Huge learning curve.

Hibernate queries are powerful, but can lead to performance issues unless special care is paid to optimization

Datavision

DataVision is an Open Source reporting tool similar to Crystal Reports. Reports can be designed using a drag-and-drop GUI. They may be run, viewed, and printed from the application or exported as HTML, XML, PDF, Excel, LaTeX2e, DocBook, or tab- or comma-delimited text files. The output files produced by LaTeX2e and DocBook can in turn be used to produce PDF, text, HTML, PostScript, and more.

DataVision is written in Java and runs almost anywhere. It can generate reports from databases or text data files. Any database with an available JDBC driver should work: Oracle, PostgreSQL, MySQL, Informix, hsqldb, Microsoft Access, Progress, and more. Columns read from text files can be separated by any character.

Report descriptions are stored as XML files. This means you can not only use the DataVision GUI but you may also edit reports using your favorite text editor

Features

  • Drag-and-drop report builder.
  • Runs anywhere Java runs
  • Works with any database that has a JDBC driver: Oracle, PostgreSQL, MySQL, Informix, hsqldb, Microsoft Access, DB/2, and more
  • Formulas, using any language supported by the Bean Scripting Framework (BSF). The default formula language shipped with DataVision is Ruby (via JRuby).
  • Reports can read data from different data sources. Currently, data sources are defined for databases and text data files (comma-separated, tab-separated, etc.)
  • Print report from DataVision
  • GUI translated into eleven languages.
  • Open source, so you get all the code to play with and use.
  • DataVision is embeddable within your own application.

Output formats

  • HTML, XML, PDF, LaTeX2e, DocBook, or tab- or comma-delimited text files, Charts, etc

Positives

  • Drag and Drop GUI for designing the report. (Report design can be modified using text-editors too, since the design-information is stored as an XML.)
  • Unlike Jasper where the dxml(containing report design information) has to be compiled every time to a .jasper file before converting the report into the required output format.

Negatives

  • Internationalization and Localization of Reports is a problem.
BIRT (Business Intelligence and Reporting Tools)

BIRT is an Eclipse-based open source reporting system for web applications, especially those based on Java and J2EE. At a high level, BIRT provides a graphical report design environment, packaged either as a plug-in for the Eclipse IDE or as a standalone report designer, and a set of runtime APIs for integrating reports into your applications. BIRT has two main components: a report designer based on Eclipse, and a runtime component that you can add to your app server. BIRT also offers a charting engine that lets you add charts to your own application.

Features

Can add a rich variety of reports to your application such as:

  • Lists - The simplest reports are lists of data. As the lists get longer, you can add grouping to organize related data together (orders grouped by customer, products grouped by supplier). If your data is numeric, you can easily add totals, averages and other summaries.
  • Charts
  • Crosstabs - Crosstabs (also called a cross-tabulation or matrix) shows data in two dimensions: sales per quarter or hits per web page.
  • Letters & Documents - Notices, form letters, and other textual documents are easy to create with BIRT. Documents can include text, formatting, lists, charts and more.
  • Compound Reports - Many reports need to combine the above into a single document. For example, a customer statement may list the information for the customer, provide text about current promotions, and provide side-by-side lists of payments and charges. A financial report may include disclaimers, charts, tables all with extensive formatting that matches corporate color schemes.

Output Formats

Simple lists of data, Charts, Crosstabs, HTML, Paginated HTML, PDF, WORD, XLS, and PostScript etc.

Positives

  • Unlike Jasper where the dxml(containing report design information) has to be compiled every time to a .jasper file before converting the report into the required output format.
  • Feature to create BIRT separates data collection from layout which gives a couple advantages like multiple data sources.

BIRT supports reusability with templates (custom report starting points) and libraries (reusable report pieces). Customized Templates helps to tightly control report writing capabilities.

Comparison Chart

Features/Tool

Jasper

DataVision

BIRT

Owned by

JasperSoft

--

Eclipse Foundation

Open Source

Yes

Yes

Yes

Database connectivity

JDBC, XML, EJBQL connection, Hibernate connection.

Any database that has a JDBC driver

JDBC connected Database, flat files, XML, Scripted(Lets you write code to access other data sources.) etc.

Internationalization & Localization Support available

Yes

No

Yes (Language packs available)

UI Tool to design Reports

Yes (iReport)

Yes

Yes

Format of Reports

Charts and Documents(PDF, HTML, XLS, CSV and XML)

Charts and Documents(PDF, HTML, XLS, CSV and XML)

Charts and Documents(PDF, HTML, XLS, CSV and XML)

Support for Hibernate queries

Yes

No

Yes

 
Conclusion:

As we see from the features of these Reporting tools, there isn’t a particular tool among the three which is the best. Each of them can have their pros and cons and it is left to the user to choose his/her favorite reporting tool after thoroughly matching the requirements of the application to the features provided by the tool. But one can rest assured that these tools have been tested and have proved their mettle in this sector and are continually upgraded

Java Reports - Comparitive Study

One of the important goals that applications must be designed for is to be able to convey complex data to the end-user in the simplest, attractive and most understandable form and ‘Reports and Charts’ go a long way in achieving this goal. Java and JEE applications being one of the leaders in the enterprise application space commonly require to display complex data in the form of Charts (such as Pie charts, bar charts etc), Documents (PDF, MS Excel etc) or Reports that are customized specifically for an application . There are a number of tools available to the Java developer that can be utilized to generate reports. This document covers some of the important aspects of the most commonly used, freely available and Open-Source Reporting tools used in the Java world.

The Contestants:

This article covers three of the commonly used Reporting tools in Java application viz. Jasper Reports , DataVision and BIRT(Business Intelligence and Reporting Tools). All three are a favorite among Java applications primarily because of the following 3 reasons –

  • Freely available.
  • Open Source.
  • Good documentation and option to avail commercial support.
Jasper Reports

JasperReports is a powerful open source Java reporting tool that has the ability to deliver rich content onto the screen, to the printer or into PDF, HTML, XLS, CSV and XML files. It is entirely written in Java and can be used in a variety of Java enabled applications, including J2EE or Web applications, to generate dynamic content. Its main purpose is to help creating page oriented, ready to print documents in a simple and flexible manner.

Features

  • Wide array of output formats
  • Flexible Data Sources : JasperReports can use any data source provider, allowing it to extend reporting capabilities to almost any third-party application. When it is not possible to access data through JDBC, or when you do not want JasperReports to interact directly with a database, you can implement a custom JasperReports Data Source. The jasper reports can fetch data from the following different data sources:
    • Database JDBC connection
    • XML file data source
    • JavaBeans set data source
    • Custom JRDataSource
    • File CSV data source
    • JRDataSourceProvider
    • Hibernate connection
    • Spring loaded Hibernate connection
    • EJBQL connection
    • Mondrian OLAP connection
    • Query Executor mode
    • Empty data source
    • Custom iReport connection
    • XMLA Server Connection
  • Internationalized and Localizable
  • Conditional printing
  • Visual text rotation
  • Integrated barcode support
  • Web-based and pixel-perfect reports

Output formats

  • PDF, HTML, XLS, CSV and XML files
  • Can create custom reports by designing the UI ourselves and feeding data to the report-design.

Completely developed in Java and compatible with any Java application

Positives

  • Has iReport as an accompanying GUI tool to design reports.
  • When it is not possible to access data through JDBC, or when you do not want JasperReports to interact directly with a database, you can implement a custom JasperReports Data Source. In addition, any report can use data from multiple data sources, which can even be of different types.
  • Widely used for reporting in Java applications.
  • Hibernate query support in addition to SQL queries

Negatives

  • Extra compilation of the report-design every time.
  • Huge learning curve.

Hibernate queries are powerful, but can lead to performance issues unless special care is paid to optimization

Datavision

DataVision is an Open Source reporting tool similar to Crystal Reports. Reports can be designed using a drag-and-drop GUI. They may be run, viewed, and printed from the application or exported as HTML, XML, PDF, Excel, LaTeX2e, DocBook, or tab- or comma-delimited text files. The output files produced by LaTeX2e and DocBook can in turn be used to produce PDF, text, HTML, PostScript, and more.

DataVision is written in Java and runs almost anywhere. It can generate reports from databases or text data files. Any database with an available JDBC driver should work: Oracle, PostgreSQL, MySQL, Informix, hsqldb, Microsoft Access, Progress, and more. Columns read from text files can be separated by any character.

Report descriptions are stored as XML files. This means you can not only use the DataVision GUI but you may also edit reports using your favorite text editor

Features

  • Drag-and-drop report builder.
  • Runs anywhere Java runs
  • Works with any database that has a JDBC driver: Oracle, PostgreSQL, MySQL, Informix, hsqldb, Microsoft Access, DB/2, and more
  • Formulas, using any language supported by the Bean Scripting Framework (BSF). The default formula language shipped with DataVision is Ruby (via JRuby).
  • Reports can read data from different data sources. Currently, data sources are defined for databases and text data files (comma-separated, tab-separated, etc.)
  • Print report from DataVision
  • GUI translated into eleven languages.
  • Open source, so you get all the code to play with and use.
  • DataVision is embeddable within your own application.

Output formats

  • HTML, XML, PDF, LaTeX2e, DocBook, or tab- or comma-delimited text files, Charts, etc

Positives

  • Drag and Drop GUI for designing the report. (Report design can be modified using text-editors too, since the design-information is stored as an XML.)
  • Unlike Jasper where the dxml(containing report design information) has to be compiled every time to a .jasper file before converting the report into the required output format.

Negatives

  • Internationalization and Localization of Reports is a problem.
BIRT (Business Intelligence and Reporting Tools)

BIRT is an Eclipse-based open source reporting system for web applications, especially those based on Java and J2EE. At a high level, BIRT provides a graphical report design environment, packaged either as a plug-in for the Eclipse IDE or as a standalone report designer, and a set of runtime APIs for integrating reports into your applications. BIRT has two main components: a report designer based on Eclipse, and a runtime component that you can add to your app server. BIRT also offers a charting engine that lets you add charts to your own application.

Features

Can add a rich variety of reports to your application such as:

  • Lists - The simplest reports are lists of data. As the lists get longer, you can add grouping to organize related data together (orders grouped by customer, products grouped by supplier). If your data is numeric, you can easily add totals, averages and other summaries.
  • Charts
  • Crosstabs - Crosstabs (also called a cross-tabulation or matrix) shows data in two dimensions: sales per quarter or hits per web page.
  • Letters & Documents - Notices, form letters, and other textual documents are easy to create with BIRT. Documents can include text, formatting, lists, charts and more.
  • Compound Reports - Many reports need to combine the above into a single document. For example, a customer statement may list the information for the customer, provide text about current promotions, and provide side-by-side lists of payments and charges. A financial report may include disclaimers, charts, tables all with extensive formatting that matches corporate color schemes.

Output Formats

Simple lists of data, Charts, Crosstabs, HTML, Paginated HTML, PDF, WORD, XLS, and PostScript etc.

Positives

  • Unlike Jasper where the dxml(containing report design information) has to be compiled every time to a .jasper file before converting the report into the required output format.
  • Feature to create BIRT separates data collection from layout which gives a couple advantages like multiple data sources.

BIRT supports reusability with templates (custom report starting points) and libraries (reusable report pieces). Customized Templates helps to tightly control report writing capabilities.

Comparison Chart

Features/Tool

Jasper

DataVision

BIRT

Owned by

JasperSoft

--

Eclipse Foundation

Open Source

Yes

Yes

Yes

Database connectivity

JDBC, XML, EJBQL connection, Hibernate connection.

Any database that has a JDBC driver

JDBC connected Database, flat files, XML, Scripted(Lets you write code to access other data sources.) etc.

Internationalization & Localization Support available

Yes

No

Yes (Language packs available)

UI Tool to design Reports

Yes (iReport)

Yes

Yes

Format of Reports

Charts and Documents(PDF, HTML, XLS, CSV and XML)

Charts and Documents(PDF, HTML, XLS, CSV and XML)

Charts and Documents(PDF, HTML, XLS, CSV and XML)

Support for Hibernate queries

Yes

No

Yes

 
Conclusion:

As we see from the features of these Reporting tools, there isn’t a particular tool among the three which is the best. Each of them can have their pros and cons and it is left to the user to choose his/her favorite reporting tool after thoroughly matching the requirements of the application to the features provided by the tool. But one can rest assured that these tools have been tested and have proved their mettle in this sector and are continually upgraded

Nov 14, 2009

Excel Generation using Dynamic Jasper-3.0

Introduction

Dynamic Jasper (DJ) is an open source free library that hides the complexity of Jasper Reports, it helps developers to save time when designing simple/medium complexity reports generating the layout of the report elements automatically.

DJ creates reports dynamically, defining at runtime the columns, column width groups, variables, fonts, charts, crosstabs, sub reports page size and everything else can be defined at design time.

More about Dynamic Jasper

Most of the features are provided directly by Jasper Reports

Dynamic column report: Columns can be defined at runtime, which means you also control (at runtime) the column positioning, width, title, etc.

Clean Excel export: One of the most valuable features that DJ provides is exporting plain reports to excel, with no data formatting, no page break, etc. This is very valuable for end users that use this report to create dynamic tables in Excel, creating these reports just with Jasper Reports can demand a lot of design time.

Auto text: Add auto text in page header and footer such as “Page 1 of 10”, “Generated on Oct. 10th 2005” or a custom text.

Styles: Each column can have its own style for its title and detail data (defining border, border color, font size, type and color, background color, etc.).

Calculation Variables: Repeating groups can have variables that hold the result of an operation on a given field (column). With DJ adding variables is a 1 line of code task.

Charts: Easy to add simple charts.

Barcode columns: As simple as adding a regular column.

Add labels in group header and footer: Dynamic Jasper enables to have labels in group header and footer, especially for each variable (on top of it) or a general label for all variables at the left.

Sub reports are supported; they can also be dynamically created.

Concatenating many reports in a single one

EXCEL GENERATION USING DYNAMIC JASPER

I. Generating excel using dynamic Jasper is the easy Process. Below code shows how to create a simple report.

  • For Column definitions, we use a new ColumnBuilder instance for each Column. The ColumnBuilder.getInstance() method returns a new instance of the builder.
  • The DynamicReportBuilder provides the methods to pass the basic parameters to the report: They are,

· addColumn( <title>, <field/property to show>, <class name of the property to show>, <width of the column> )

· addGroups (<number of columns to group by>)

· setTitle(...)

· setSubtitle( ...)

The code snippet:
 
DynamicReportBuilder drb = new DynamicReportBuilder();

AbstractColumn firstName = ColumnBuilder.getInstance()
.setColumnProperty("firstName", String.class.getName())
.setTitle("First Name")
.setWidth(15);

AbstractColumn lastName = ColumnBuilder.getInstance()
.setColumnProperty("lastName", String.class.getName())
.setTitle("Last Name")
.setWidth(15);

AbstractColumn Age = ColumnBuilder.getInstance()
.setColumnProperty("lastName", Integer.class.getName())
.setTitle("Last Name")
.setWidth(15);

drb.addColumn(firstName);
drb.addColumn(lastName);
drb.addColumn(Age);
drb.setUseFullPageWidth(true);


Snippet brief:


•    setColumnProperty:

        Defines the field of the data source that the column will show, also its type (Integer, Float, BigDecimal, Double, Date, etc)



•    setTitle:

        Set the title for the column



•    setWidth

        Set the width of the column



•    addColumn

        Add the columns to the report (through the builder) in the order we want them to appear



•    setUseFullPageWidth(<Boolean>)

         If true, the columns width will be resized proportionally until meet the page width



II. Moving the column into Excel sheet


Ø The DynamicReportBuilder builds DynamicReport objects, this object contains the main options of the report (title, subtitle, styles, page size, orientation and a list of columns and groups)



DynamicReport dynamicReport = drb.build();

// Create a JRDataSource and dataList is the list from DB

JRDataSource dataSource = new JRBeanCollectionDataSource(dataList);

// Creates the JasperPrint object, pass as a dynamicReport and DataSource
as the Parameter

JasperPrint jasperPrint = DynamicJasperHelper
.generateJasperPrint(dynamicReport,
new ClassicLayoutManager(), dataSource);

// Initializing the finalbyteArray(byte array) and ServletOutputStream

byte[] finalbyteArray = null;
ServletOutputStream sout = null;

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();


// Using JRXlsExporter to exports a JasperReports document to XLS format.


JRXlsExporter exporterXLS = new JRXlsExporter();


// Excel Spacification Parameter


exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, outputStream);
exporterXLS.exportReport();
finalbyteArray = outputStream.toByteArray();


// This will give you the popup window with the Option(Open,Save or Cancel)

response.setContentType("application/xsl");
response.setContentLength(finalbyteArray.length);

// filename,which is used to save the file

response.setHeader("Content-Disposition", "attachment; filename="excel.xls");
sout = response.getOutputStream();


//Writing the final byteArray into ServletOutputStream
sout.write(finalbyteArray);
sout.flush();
DynamicReport dynamicReport = drb.build();

// Create a JRDataSource and dataList is the list from DB

JRDataSource dataSource = new JRBeanCollectionDataSource(dataList);

// Creates the JasperPrint object, pass as a dynamicReport and DataSource
as the Parameter

JasperPrint jasperPrint = DynamicJasperHelper
.generateJasperPrint(dynamicReport,
new ClassicLayoutManager(), dataSource);


ADDING GROUPS



//define the criteria column to group by (some column: for eg., state)
// GroupBuilder is used to group the columns

GroupBuilder gb1 = new GroupBuilder();
DJGroup dgGroup = gb1.setCriteriaColumn((PropertyColumn) state)
.setGroupLayout(GroupLayout.DEFAULT).build();

//add the group to the DynamicReportBuilder

drb.addGroup(dgGroup);


ADDING STYLE



Ø To add style to column header or tittle, use Style class



Style headerStyle = new Style();


Ø To set column header Font Face,textcolor,borderColor and Transparency



headerStyle.setFont(Font.ARIAL_SMALL_BOLD);
headerStyle.setTextColor(Color.BLACK);
headerStyle.setTransparency(Transparency.OPAQUE);
headerStyle.setBorderColor(Color.BLACK);


Ø To set report title Font Face,textcolor,borderColor and Alignment



Style titleStyle = new Style();
titleStyle.setFont(Font.ARIAL_MEDIUM);
titleStyle.setBorder(Border.THIN);
titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
titleStyle.setVerticalAlign(VerticalAlign.MIDDLE);
titleStyle.setBorderColor(Color.LIGHT_GRAY);


ADDING HEADER AND/OR FOOTER TO A REPORT



Ø To add Header or Footer to the report



drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y,AutoText.POSITION_FOOTER, AutoText.ALIGMENT_RIGHT, 30, 30);
drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_FOOTER,
AutoText.ALIGMENT_LEFT, AutoText.PATTERN_DATE_DATE_TIME,285,285);

drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_HEADER
AutoText.ALIGMENT_LEFT, AutoText.PATTERN_DATE_DATE_TIME,285,285);


TWO TABLES IN EXCEL



Ø Creating multiple Table in Excel is same as creating the Single Table, but instead of Passing single DataSource and Dynamic Report, you need to pass multiple Datasource and Dynamic Report.



// Creating two DynamicReportBuilder  instant
DynamicReportBuilder firstdrb = new DynamicReportBuilder();
DynamicReportBuilder Seconddrb = new DynamicReportBuilder();

// First Table will contain two Columns (firstName(<String>) and LastName(<String>))
AbstractColumn firstName = ColumnBuilder.getInstance()
.setColumnProperty("firstName", String.class.getName())
.setTitle("First Name")
.setWidth(15);

AbstractColumn lastName = ColumnBuilder.getInstance()
.setColumnProperty("lastName", String.class.getName())
.setTitle("Last Name")
.setWidth(15);

// Second Table will contain two Columns (Age(<Integer>) and State<String>)
AbstractColumn Age = ColumnBuilder.getInstance()
.setColumnProperty("lastName", Integer.class.getName())
.setTitle("Last Name")
.setWidth(15);

AbstractColumn State = ColumnBuilder.getInstance()
.setColumnProperty("lastName", String.class.getName())
.setTitle("Last Name")
.setWidth(15);

// Adding firstName and lastName in firstdrb (DynamicReportBuilder)
firstdrb.addColumn(firstName);
firstdrb.addColumn(lastName);
firstdrb.setUseFullPageWidth(true);

// Adding Age and state in firstdrb (DynamicReportBuilder
Seconddrb.addColumn(Age);
Seconddrb.addColumn(state);
Seconddrb.setUseFullPageWidth(true);


//Initializing JRDataSource
JRDataSource firstjrDataSource = null;
JRDataSource secondjrDataSource1 = null;

//Initializing DynamicReport
DynamicReport firstdReport = null;
DynamicReport seconddReport = null;

//Initializing JasperPrint
JasperPrint jPrint = null;
JasperPrint jp1 = null;


// Building both the report!
if(firstdrb!= null){
firstdReport = firstdrb.build();
}
if(Seconddrb!= null){
seconddReport = Seconddrb.build();
}

// Passing firstList to firstjrDataSource
if(firstList!= null && firstList.size() > 0){
firstjrDataSource = new JRBeanCollectionDataSource(firstList);
}


// Passing secondList to secondjrDataSource1(
if(secondList!= null && secondList.size() > 0){
secondjrDataSource1 = new JRBeanCollectionDataSource(secondList);
}

// Creating two JasperPrint(jPrint,jp1) instance and both the List to JasperPrint
if(dReport != null && jrDataSource != null){
jPrint = DynamicJasperHelper.generateJasperPrint(firstdReport,
new ClassicLayoutManager(),firstjrDataSource);
}

if(dReport1 != null && jrDataSource1 != null){
jp1 = DynamicJasperHelper.generateJasperPrint(seconddReport,
new ClassicLayoutManager(), secondjrDataSource1);
}

// Iterating both the JasperPrint(jPrint ,jp1), getting the tables as separate pages and finally adding the pages to Single Jasperprint.
JasperPrint printAll = new JasperPrint();
if(jPrint != null){
for(int i = 0; i < jPrint.getPages().size(); i++){
printAll.addPage((JRPrintPage)jPrint.getPages().get(i));
}
}

if(jp1 != null){
for(int j = 0; j < jp1.getPages().size(); j++){
printAll.addPage((JRPrintPage)jp1.getPages().get(j));
}
}

// Setting the Width and Height For the table
printAll.setPageHeight(842);
printAll.setPageWidth(595);


SNAPSHOT


clip_image002



USED JARS




  • DynamicJasper-3.0.6.jar



  • jasperreports-2.0.2.jar



  • itext-1.3.jar



  • poi-3.0.1.jar



Website for Reference




Excel Generation using Dynamic Jasper-3.0

Introduction

Dynamic Jasper (DJ) is an open source free library that hides the complexity of Jasper Reports, it helps developers to save time when designing simple/medium complexity reports generating the layout of the report elements automatically.

DJ creates reports dynamically, defining at runtime the columns, column width groups, variables, fonts, charts, crosstabs, sub reports page size and everything else can be defined at design time.

More about Dynamic Jasper

Most of the features are provided directly by Jasper Reports

Dynamic column report: Columns can be defined at runtime, which means you also control (at runtime) the column positioning, width, title, etc.

Clean Excel export: One of the most valuable features that DJ provides is exporting plain reports to excel, with no data formatting, no page break, etc. This is very valuable for end users that use this report to create dynamic tables in Excel, creating these reports just with Jasper Reports can demand a lot of design time.

Auto text: Add auto text in page header and footer such as “Page 1 of 10”, “Generated on Oct. 10th 2005” or a custom text.

Styles: Each column can have its own style for its title and detail data (defining border, border color, font size, type and color, background color, etc.).

Calculation Variables: Repeating groups can have variables that hold the result of an operation on a given field (column). With DJ adding variables is a 1 line of code task.

Charts: Easy to add simple charts.

Barcode columns: As simple as adding a regular column.

Add labels in group header and footer: Dynamic Jasper enables to have labels in group header and footer, especially for each variable (on top of it) or a general label for all variables at the left.

Sub reports are supported; they can also be dynamically created.

Concatenating many reports in a single one

EXCEL GENERATION USING DYNAMIC JASPER

I. Generating excel using dynamic Jasper is the easy Process. Below code shows how to create a simple report.

  • For Column definitions, we use a new ColumnBuilder instance for each Column. The ColumnBuilder.getInstance() method returns a new instance of the builder.
  • The DynamicReportBuilder provides the methods to pass the basic parameters to the report: They are,

· addColumn( <title>, <field/property to show>, <class name of the property to show>, <width of the column> )

· addGroups (<number of columns to group by>)

· setTitle(...)

· setSubtitle( ...)

The code snippet:
 
DynamicReportBuilder drb = new DynamicReportBuilder();

AbstractColumn firstName = ColumnBuilder.getInstance()
.setColumnProperty("firstName", String.class.getName())
.setTitle("First Name")
.setWidth(15);

AbstractColumn lastName = ColumnBuilder.getInstance()
.setColumnProperty("lastName", String.class.getName())
.setTitle("Last Name")
.setWidth(15);

AbstractColumn Age = ColumnBuilder.getInstance()
.setColumnProperty("lastName", Integer.class.getName())
.setTitle("Last Name")
.setWidth(15);

drb.addColumn(firstName);
drb.addColumn(lastName);
drb.addColumn(Age);
drb.setUseFullPageWidth(true);


Snippet brief:


•    setColumnProperty:

        Defines the field of the data source that the column will show, also its type (Integer, Float, BigDecimal, Double, Date, etc)



•    setTitle:

        Set the title for the column



•    setWidth

        Set the width of the column



•    addColumn

        Add the columns to the report (through the builder) in the order we want them to appear



•    setUseFullPageWidth(<Boolean>)

         If true, the columns width will be resized proportionally until meet the page width



II. Moving the column into Excel sheet


Ø The DynamicReportBuilder builds DynamicReport objects, this object contains the main options of the report (title, subtitle, styles, page size, orientation and a list of columns and groups)



DynamicReport dynamicReport = drb.build();

// Create a JRDataSource and dataList is the list from DB

JRDataSource dataSource = new JRBeanCollectionDataSource(dataList);

// Creates the JasperPrint object, pass as a dynamicReport and DataSource
as the Parameter

JasperPrint jasperPrint = DynamicJasperHelper
.generateJasperPrint(dynamicReport,
new ClassicLayoutManager(), dataSource);

// Initializing the finalbyteArray(byte array) and ServletOutputStream

byte[] finalbyteArray = null;
ServletOutputStream sout = null;

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();


// Using JRXlsExporter to exports a JasperReports document to XLS format.


JRXlsExporter exporterXLS = new JRXlsExporter();


// Excel Spacification Parameter


exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, outputStream);
exporterXLS.exportReport();
finalbyteArray = outputStream.toByteArray();


// This will give you the popup window with the Option(Open,Save or Cancel)

response.setContentType("application/xsl");
response.setContentLength(finalbyteArray.length);

// filename,which is used to save the file

response.setHeader("Content-Disposition", "attachment; filename="excel.xls");
sout = response.getOutputStream();


//Writing the final byteArray into ServletOutputStream
sout.write(finalbyteArray);
sout.flush();
DynamicReport dynamicReport = drb.build();

// Create a JRDataSource and dataList is the list from DB

JRDataSource dataSource = new JRBeanCollectionDataSource(dataList);

// Creates the JasperPrint object, pass as a dynamicReport and DataSource
as the Parameter

JasperPrint jasperPrint = DynamicJasperHelper
.generateJasperPrint(dynamicReport,
new ClassicLayoutManager(), dataSource);


ADDING GROUPS



//define the criteria column to group by (some column: for eg., state)
// GroupBuilder is used to group the columns

GroupBuilder gb1 = new GroupBuilder();
DJGroup dgGroup = gb1.setCriteriaColumn((PropertyColumn) state)
.setGroupLayout(GroupLayout.DEFAULT).build();

//add the group to the DynamicReportBuilder

drb.addGroup(dgGroup);


ADDING STYLE



Ø To add style to column header or tittle, use Style class



Style headerStyle = new Style();


Ø To set column header Font Face,textcolor,borderColor and Transparency



headerStyle.setFont(Font.ARIAL_SMALL_BOLD);
headerStyle.setTextColor(Color.BLACK);
headerStyle.setTransparency(Transparency.OPAQUE);
headerStyle.setBorderColor(Color.BLACK);


Ø To set report title Font Face,textcolor,borderColor and Alignment



Style titleStyle = new Style();
titleStyle.setFont(Font.ARIAL_MEDIUM);
titleStyle.setBorder(Border.THIN);
titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
titleStyle.setVerticalAlign(VerticalAlign.MIDDLE);
titleStyle.setBorderColor(Color.LIGHT_GRAY);


ADDING HEADER AND/OR FOOTER TO A REPORT



Ø To add Header or Footer to the report



drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y,AutoText.POSITION_FOOTER, AutoText.ALIGMENT_RIGHT, 30, 30);
drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_FOOTER,
AutoText.ALIGMENT_LEFT, AutoText.PATTERN_DATE_DATE_TIME,285,285);

drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_HEADER
AutoText.ALIGMENT_LEFT, AutoText.PATTERN_DATE_DATE_TIME,285,285);


TWO TABLES IN EXCEL



Ø Creating multiple Table in Excel is same as creating the Single Table, but instead of Passing single DataSource and Dynamic Report, you need to pass multiple Datasource and Dynamic Report.



// Creating two DynamicReportBuilder  instant
DynamicReportBuilder firstdrb = new DynamicReportBuilder();
DynamicReportBuilder Seconddrb = new DynamicReportBuilder();

// First Table will contain two Columns (firstName(<String>) and LastName(<String>))
AbstractColumn firstName = ColumnBuilder.getInstance()
.setColumnProperty("firstName", String.class.getName())
.setTitle("First Name")
.setWidth(15);

AbstractColumn lastName = ColumnBuilder.getInstance()
.setColumnProperty("lastName", String.class.getName())
.setTitle("Last Name")
.setWidth(15);

// Second Table will contain two Columns (Age(<Integer>) and State<String>)
AbstractColumn Age = ColumnBuilder.getInstance()
.setColumnProperty("lastName", Integer.class.getName())
.setTitle("Last Name")
.setWidth(15);

AbstractColumn State = ColumnBuilder.getInstance()
.setColumnProperty("lastName", String.class.getName())
.setTitle("Last Name")
.setWidth(15);

// Adding firstName and lastName in firstdrb (DynamicReportBuilder)
firstdrb.addColumn(firstName);
firstdrb.addColumn(lastName);
firstdrb.setUseFullPageWidth(true);

// Adding Age and state in firstdrb (DynamicReportBuilder
Seconddrb.addColumn(Age);
Seconddrb.addColumn(state);
Seconddrb.setUseFullPageWidth(true);


//Initializing JRDataSource
JRDataSource firstjrDataSource = null;
JRDataSource secondjrDataSource1 = null;

//Initializing DynamicReport
DynamicReport firstdReport = null;
DynamicReport seconddReport = null;

//Initializing JasperPrint
JasperPrint jPrint = null;
JasperPrint jp1 = null;


// Building both the report!
if(firstdrb!= null){
firstdReport = firstdrb.build();
}
if(Seconddrb!= null){
seconddReport = Seconddrb.build();
}

// Passing firstList to firstjrDataSource
if(firstList!= null && firstList.size() > 0){
firstjrDataSource = new JRBeanCollectionDataSource(firstList);
}


// Passing secondList to secondjrDataSource1(
if(secondList!= null && secondList.size() > 0){
secondjrDataSource1 = new JRBeanCollectionDataSource(secondList);
}

// Creating two JasperPrint(jPrint,jp1) instance and both the List to JasperPrint
if(dReport != null && jrDataSource != null){
jPrint = DynamicJasperHelper.generateJasperPrint(firstdReport,
new ClassicLayoutManager(),firstjrDataSource);
}

if(dReport1 != null && jrDataSource1 != null){
jp1 = DynamicJasperHelper.generateJasperPrint(seconddReport,
new ClassicLayoutManager(), secondjrDataSource1);
}

// Iterating both the JasperPrint(jPrint ,jp1), getting the tables as separate pages and finally adding the pages to Single Jasperprint.
JasperPrint printAll = new JasperPrint();
if(jPrint != null){
for(int i = 0; i < jPrint.getPages().size(); i++){
printAll.addPage((JRPrintPage)jPrint.getPages().get(i));
}
}

if(jp1 != null){
for(int j = 0; j < jp1.getPages().size(); j++){
printAll.addPage((JRPrintPage)jp1.getPages().get(j));
}
}

// Setting the Width and Height For the table
printAll.setPageHeight(842);
printAll.setPageWidth(595);


SNAPSHOT


clip_image002



USED JARS




  • DynamicJasper-3.0.6.jar



  • jasperreports-2.0.2.jar



  • itext-1.3.jar



  • poi-3.0.1.jar



Website for Reference




Nov 13, 2009

Actuate e.Report Designer Professional and Report Bursting

Introduction


Actuate e.Report Designer Professional is a report designing, building tool. It can connect with various databases and retrieve the data and display in richly formatted report. There are various specialized report components, such as charts and crosstabs to display data in the desired format. After the report is created and previewed, the generated executable file can be published to the Actuate iServer.


Integrated Development Environment (IDE) of e.Report Designer Professional



There are various browsers available in the e.Report Designer Professional which makes the IDE. All these browser works independently and can be docked and place as per the convenience. It can be closed and again re-opened from view menu in the main menu bar. The various browsers are


Report Structure: This consist the structure of the report and list all the component of the report.


Libraries: This consist report components or an Actuate Basic function for reuse in multiple report designs. These components can be shared by all the developers.


Properties: This display all the property of the selected components. These properties can be changed as per need. This also contains the tab for method, which contains the method that can be overridden to get the desire output. It display list of variables and class details.


Fields: This display all the fields fetched from the database.


Toolbox: This contains all the components which can be used to develop a report.


Output Browser: This displays the output and the error in the reports.


Scratch Pad: This is the place where unnecessary report component can be place during the build.


Layout: This is the place where designing and building of the reports are done.


Data tab: This is the place where the query is written to fetch the data from connected data source.


Debug tab: When there is an error in the report, this place comes handy.


View tab: This is where we view the report build.






Actuate e.Report Designer Professional.


Various Type of file of Actuate e.Report Designer Professional:


There are various kind of file generated in each stage of the report design procedure. Each file has a specific meaning and use. The process of generation is displayed below.






Different file generated in Actuate e.Report Designer Professional.


.rod: When the report is designed, the report object design (.rod) file is created which contains all the design.


.bas: Once the report is designed when it is build, it creates the basic actuate source (.bas) file. It contains all the code generated from .rod file. This file is used to debug the error in the report.


.rov: Report object variable (.rov) is a supporting file which contains the parameter and variable. This file is also created during the compilation of .rod file.


.rox: When we compile the .bas file it generate report object executable (.rox) file. This is the file which is run to view the report.


.roi: When we run the .rox file, it creates a report object instance (.roi) file. This file contains objects that store the finished report’s structure and data.






The various type of file used by Actuate e.Report Designer Professional.


Report Bursting:



Report Bursting is a feature of the e.Report Designer Professional where a single .rox file generates multiple .roi files. It is kind of linked reports where clicking in any of the link, generates the another .roi file which display the detail as per the selected linked.


How to make a report which can generate multiple .roi file for a .rox file?


1. Create a new file by clicking File->New.


2. Select Blank Information Object. It creates a blank report structure with report component, report structure and connection.


3. Select Textual Query Source, and then click on data tab. The window screen appears where SQL query is written.





Textual Query Editor.


4. Design the first report as you wish by using various components available in toolbox.






5. Select the field based on which you want to create another report.


6. Right click on the field in layout screen and then click properties.


7. There is a property called linking, expand the properties and there is link exp:


8. Click on open button in right hand side of textbox and write the linking expression in following format.


"Supervisor-" & [SNAME] & ".roi"


The format contains any string you wish to display in the name of .roi file generated and the field used to link the report with .roi extension.






9. Click ok to close the hyperlink builder window.


10. Now place a new report component from the toolbox in the content section of the report section available in report structure.


11. Design the second report within the new report component added.






12. Now override the method of the report component to link this report component with the link.


13. To override, select the report component in report structure.


14. Right click on the report component in report structure and then click properties.


15. Select the method tab and double click the method named: Function SuggestRoiName( row As AcDataRow ) As String


16. Now a new screen is shown in layout screen where custom codes can be written. Insert the code between the the beginning and end of the function.


SuggestRoiName = "Supervisor-" & row.GetValue( "SNAME" ) & ".roi"


The format for the system variable SuggestRoiName is same as that of the one in linking expression. The only difference is the database field [SNAME] is replaced by the row.GetValue() function. This function gets the value from the current row whose column name is same as that of the string passed. In this case the string is same as that of the database field in linking expression.





17. Once this is done save the design by clicking file->save.


18. To test the report, click Report -> Build and Run.


19. The output screen displays the report being compiled. Then it creates the .roi file which contains the main report.






20. Now clicking in the name Scott Waits will generate another report, which will display the detail as per the design.





21. Now clicking in the name Siva Ranjani Rajamani will generate another report, which will display the detail as per the design.




 





Conclusion



Using Actuate e.Report Designer Professional, we can generate powerful reports with charts and crosstabs with ease. The concept such as report bursting shows the power of simple code overriding. The custom code opens the lots of possibilities.


Reference



  • Actuate User Guide

Actuate e.Report Designer Professional and Report Bursting

Introduction


Actuate e.Report Designer Professional is a report designing, building tool. It can connect with various databases and retrieve the data and display in richly formatted report. There are various specialized report components, such as charts and crosstabs to display data in the desired format. After the report is created and previewed, the generated executable file can be published to the Actuate iServer.


Integrated Development Environment (IDE) of e.Report Designer Professional



There are various browsers available in the e.Report Designer Professional which makes the IDE. All these browser works independently and can be docked and place as per the convenience. It can be closed and again re-opened from view menu in the main menu bar. The various browsers are


Report Structure: This consist the structure of the report and list all the component of the report.


Libraries: This consist report components or an Actuate Basic function for reuse in multiple report designs. These components can be shared by all the developers.


Properties: This display all the property of the selected components. These properties can be changed as per need. This also contains the tab for method, which contains the method that can be overridden to get the desire output. It display list of variables and class details.


Fields: This display all the fields fetched from the database.


Toolbox: This contains all the components which can be used to develop a report.


Output Browser: This displays the output and the error in the reports.


Scratch Pad: This is the place where unnecessary report component can be place during the build.


Layout: This is the place where designing and building of the reports are done.


Data tab: This is the place where the query is written to fetch the data from connected data source.


Debug tab: When there is an error in the report, this place comes handy.


View tab: This is where we view the report build.






Actuate e.Report Designer Professional.


Various Type of file of Actuate e.Report Designer Professional:


There are various kind of file generated in each stage of the report design procedure. Each file has a specific meaning and use. The process of generation is displayed below.






Different file generated in Actuate e.Report Designer Professional.


.rod: When the report is designed, the report object design (.rod) file is created which contains all the design.


.bas: Once the report is designed when it is build, it creates the basic actuate source (.bas) file. It contains all the code generated from .rod file. This file is used to debug the error in the report.


.rov: Report object variable (.rov) is a supporting file which contains the parameter and variable. This file is also created during the compilation of .rod file.


.rox: When we compile the .bas file it generate report object executable (.rox) file. This is the file which is run to view the report.


.roi: When we run the .rox file, it creates a report object instance (.roi) file. This file contains objects that store the finished report’s structure and data.






The various type of file used by Actuate e.Report Designer Professional.


Report Bursting:



Report Bursting is a feature of the e.Report Designer Professional where a single .rox file generates multiple .roi files. It is kind of linked reports where clicking in any of the link, generates the another .roi file which display the detail as per the selected linked.


How to make a report which can generate multiple .roi file for a .rox file?


1. Create a new file by clicking File->New.


2. Select Blank Information Object. It creates a blank report structure with report component, report structure and connection.


3. Select Textual Query Source, and then click on data tab. The window screen appears where SQL query is written.





Textual Query Editor.


4. Design the first report as you wish by using various components available in toolbox.






5. Select the field based on which you want to create another report.


6. Right click on the field in layout screen and then click properties.


7. There is a property called linking, expand the properties and there is link exp:


8. Click on open button in right hand side of textbox and write the linking expression in following format.


"Supervisor-" & [SNAME] & ".roi"


The format contains any string you wish to display in the name of .roi file generated and the field used to link the report with .roi extension.






9. Click ok to close the hyperlink builder window.


10. Now place a new report component from the toolbox in the content section of the report section available in report structure.


11. Design the second report within the new report component added.






12. Now override the method of the report component to link this report component with the link.


13. To override, select the report component in report structure.


14. Right click on the report component in report structure and then click properties.


15. Select the method tab and double click the method named: Function SuggestRoiName( row As AcDataRow ) As String


16. Now a new screen is shown in layout screen where custom codes can be written. Insert the code between the the beginning and end of the function.


SuggestRoiName = "Supervisor-" & row.GetValue( "SNAME" ) & ".roi"


The format for the system variable SuggestRoiName is same as that of the one in linking expression. The only difference is the database field [SNAME] is replaced by the row.GetValue() function. This function gets the value from the current row whose column name is same as that of the string passed. In this case the string is same as that of the database field in linking expression.





17. Once this is done save the design by clicking file->save.


18. To test the report, click Report -> Build and Run.


19. The output screen displays the report being compiled. Then it creates the .roi file which contains the main report.






20. Now clicking in the name Scott Waits will generate another report, which will display the detail as per the design.





21. Now clicking in the name Siva Ranjani Rajamani will generate another report, which will display the detail as per the design.




 





Conclusion



Using Actuate e.Report Designer Professional, we can generate powerful reports with charts and crosstabs with ease. The concept such as report bursting shows the power of simple code overriding. The custom code opens the lots of possibilities.


Reference



  • Actuate User Guide

Text Widget

Copyright © Vinay's Blog | Powered by Blogger

Design by | Blogger Theme by