Hello everyone, in the previous post, I have guided you how to install Birt Report in Eclipse (as a plugin) to be able to perform operations related to report rendering in a fairly detailed manner.
And in this next article, I will join you in creating a simple Excel file report, using the Birt Report utility that we installed in the previous post. This report will read data from the database and output as an Excel file (*.xlsx).
I. Instructions for creating reports with BIRT REPORT and ECLIPSE
Below is the interface we will work with the report as in the previous article I guided you to install.
- (first) are 3 important tabs that are
Palette(used to design templates),
Data Explorer(connect to data),
Resource Explorer(contains template files)
- (2) are elements such as tables, text, images, graphs, etc. that we can insert into the report.
- (3) This is the Template interface where we design the report
- (4) includes components related to the format configuration for the report.
Okay, that’s all the basic components for us to work with the report in Birt Report. For now, let’s go into the details of designing a report.
#first. General format for reports
+ Step 1: In the tab
Master Page You can adjust the parameters as shown below. This setting will help our report (if exported in PDF format) will be the page size
A4 placed horizontally.
+ Step 2: Then, I will drag a table into the template and define the number of columns and detailed rows.
Why do I need a board?
Well, simply because reports often render data in the form of a table (also in the form of a chart), I must have a table like the image below.
Regarding the table structure in Birt Report, there will be 3 components:
- (first) Header Row: Allows us to define fixed elements such as headers, column names, etc. of the report
- (2) Detail Row: This will be where we dump the data from the database and it will display dynamically according to the data in the database as well as our query.
- (3) Footer Row: Allows us to define fixed information such as when to render the report, who renders the report, etc.
+ Step 3: Next will be a few operations that we can work with the report, that is
Merge Cells. You select the cells you want to merge => then right-click and select
Merge Cell as shown below.
Reason must Merge Cells Anyone who works with Excel knows why, right?
+ Step 4: After Merge cells are finished, drag into the merged cell a text with the content as shown below to use as the report title.
+ Step 5: Next, to insert more rows, select a certain row => then right-click and select:
The same, similar for columns too: You choose
Insert=> and choose
Column to the Right (Left)
+ Step 6: After adding the rows, I define the names for the corresponding columns as shown below. So we have the general format for the report done.
#2. Connect the table to the database
To be able to get data from the database and display it in the report, we need to create
Data Source and
+ Step 1: First I will create
Data Sources to connect to the database: You choose
Data Explorer =>
Data Source => choose
New Data Source as shown below.
+ Step 2: In this article, I use MySQL and connect via
JDBC So I will choose:
Create from a data source type in the following list => choose
JDBC Data Source => and choose
Next as shown below.
+ Step 3: Initially you will have to add the Driver, there are many ways to add. Here I will directly download the file
You can find the files here: https://mvnrepository.com/artifact/mysql/mysql-connector-java
Please note that you should choose the correct version corresponding to the version of the database (or higher is fine). Here’s the example I’m using
MySQL 8.0.15then i download the file
Specifically, you can see the image below for a better understanding.
+ Step 4: After uploading the connector, then you select the corresponding Driver => then fill in the connection information to the database => and click
Test Connection… If the message is as shown below, the connection is successful.
+ Step 5: Next we will create Data Sets: You choose
Data Explorer =>
Data Sets => choose
New Data Set
+ Step 6: Selection
Data Source you just created in the previous step. Data Set Type you choose:
SQL Select Query to use the sentence
SQL SELECT is a data query statement.
+ Step 7: Now you will have to define a query to get the data, here I get all the fields from the table.
student in your database.
+ Step 8: After defining the query and press
Finish then you can preview (Preview) the data that the query gets (here I take all the records so the result is exactly the same as in the database).
+ Step 9: Okay, so we’ve got the data. Next we will have to
Binding this data into our report.
Back to the report, you click on the table that you want to bind data. In the tab
Binding => Select
Data Set as shown below.
Step 10: After data binding, we will drag the corresponding fields from the Data Set to the corresponding fields in the Template as shown below.
+ Step 11: The final step is to render the report. Here I render the Excel file, so I will choose as shown below. There are also many other file formats that you can choose from.
Okay, after rendering, I get an Excel file report with data taken from the database.
Well, so in this article, I have created with you guys a simple report in Excel file format using the Birt Report utility that connects and retrieves data from the database in Eclipse.
In fact, the reports that we need to do will be a lot more complicated than the example we made above. But in this tutorial, I hope that newcomers will easily understand how to create a dynamic report of data using Birt Report.
If you find the article good, don’t forget to comment in the comment section to let me know. See you in the next posts!
CTV: Nguyen Duc Canh – Blogchiasekienthuc.com
Note: Was this article helpful to you? Don’t forget to rate the article, like and share it with your friends and family!