Your message has been sent.
This article has been saved to your account.
Go to my account
This article has been emailed to your Kindle.
Send this article
Complete the form below to send this article, Use of Stylesheets for Report Designing using BIRT, to a friend (or to yourself). We will never share your details (or your friend's) with anyone. For more information, read our Privacy Policy.
BIRT is an open source business intelligence and reporting tool built on top of the Eclipse Framework. BIRT is used by developers for building reports that can best represent data and tell a story of that data that is easy to follow. In addition, BIRT can be integrated into a product to allow that product to provide reporting capabilities.
In this article by John Ward,author of BIRT 2.6 Data Analysis and Reporting we will look at how BIRT uses stylesheets in report designs and how styles can be grouped in a library to create themes. This will allow us to have certain sets of styles ready for use any time we develop a report so that we, as a report developer, can focus strictly on the technical aspects of the report while maintaining a consistent visual presentation.
Stylesheets
BIRT, being a web-based reporting environment, takes a page from general web development toolkits by importing stylesheets. However, BIRT stylesheets function slightly differently to regular stylesheets in a web development environment.
We are going to add on to the Customer Orders report we have been working with, and will create some styles that will be used in this report.
- Open Customer Order.rptDesign.
- Right-click on the getCustomerInformation dataset and choose Insert into Layout.
- Modify the table visually to look like the next figure.

Create a new dataset called getCustomerOrders using the following query: //insert code 1
- Link the dataset parameter to rprmCustomerID.
- Save the dataset, right-click on it, and select Insert to layout.

- Select the first ORDERNUMBER column.

- Under the Property Editor, Select Advanced.

- In the Property Editor, go to the Suppress duplicates option, and change it to true. This will prevent the OrderNumber data item from repeating the value it displays down the page.

- In the Outline, right-click on Styles and choose New Style….

- In the Pre-Defined Style drop down, choose table-header. A predefined style is an element that is already defined in the BIRT report. When selecting a predefined style, this will affect every element of that type within a report. In this case, for every table in the report, the table header will have this style applied.

- Under the Font section, apply the following settings:
- Font: Sans-Serif
- Font Color: White
- Size: Large
- Weight: Bold
- Under the Background section, set the Background Color to >b>Black.
- Click OK.
Now, when we run the report, we can see that the header line is formatted with a black background and white font.

Custom stylesheets
In the example we just saw, we didn't have to apply this style to any element, it was automatically applied to the header of the order details table as it was using a predefined style. This would be the case for any table that had the header row populated with something and the same is the case for any of the predefined styles in BIRT. So next, let's look at a custom defined style and apply it to our customer information table.
- Right-click on the Styles section under the Outline tab and create a new style.

- Under the Custom Style textbox, enter CustomerHeaderInfo.

- Under the Font section, enter the following information:
- Font: Sans Serif
- Color: White
- Size: Large
- Weight: Bold
- Under the Background section, set the Background Color to Gray.
- Under the Box section, enter 1 points for all sections.
- Under the Border section, enter the following information:
- Style (All): Solid
- Color (All): White
- Width (All): Thin
- Click OK and then click Save.
- Select the table which contains the customer information.

- Select the first column.

- Under the Property Editor, in the list box for the Styles, select CustomerHeaderInfo.

- The preview report will look like the following screenshot:

- Right-click on the Styles section, and create a new custom style called CustomerHeaderData.

- Under Box, put in 1 points for all fields.
- Under Border, enter the following information:
- Style – Top: Solid
- Style – Bottom: Solid
- Color (All): Gray
- Click OK.
- Select the Customer Information table.

- Select the second column.

- Right-click on the column selector and select Style | Apply Style | CustomHeaderData.

- The finished report should look something like the next screenshot:

Editing stylesheets
So, now we have two custom styles and one predefined style defined in the report.However, we need to make a change. If we look at this preceding example, the gray lines in the data section of our header do not match the white lines of the label section. Normally such tedious visual elements are the concerns for graphic designers, but in this case this provides us with the perfect excuse to look at editing stylesheets.
The following example will take a look at editing the column of the header information so that the lines are gray instead of white. Editing stylesheets is a fairly trivial task, where simply double-clicking existing styles brings up the style editor.
- In the Outline tab, under the Style section, double-click on the CustomHeaderInfo style or right-click and select Edit Style….

- Select the Border Section. Under the Top and Bottom colors, select Gray.

That was easy enough. Let's take a look at the report as it stands:

There is a gap of a few pixels between the label column and the data column.The following steps show how to get rid of that gap:
- Select CustomHeaderInfo and open it for editing.
- Select Border. Change the Left and Right line style to No Line Style.

- Repeat steps 1 to 3 for CustomHeaderData.

Alternating row colors using Highlights
So far the report we are designing is coming along nicely. However, the details section leaves a little to be desired visually. It is hard to distinguish lines from each other, and it would be nice to have the first line of a new order be of a different color to distinguish it from the previous order. Well, we are in luck. BIRT provides a nice capability called Highlight that allows us to change formatting options based on a particular condition. What follows is a frequently requested report feature. We will add in an alternating row color to simulate the old fashioned "green bar" type reports.
Highlighting can be applied in one of two ways. It can be applied either to an element directly or in a style. There really is no difference in editing a style between the two. I will cover both methods.
First, let's look at applying the alternating row color through a style:
- Create a new style called detailAlternatingRowColor. A single word must be used, else an error will be thrown.

- Select Highlights from the list of categories. Select Add….

- Use the following condition: row.__rownum % 2. This is an expression that will select every other row.
- Set the operand to Equals to. This defines what type of comparison is used between the expression and what it expects as its final value.
- Set the value to 0. This defines what the expression's final value will cause this highlight to trigger.
- Set the Background color to Silver.

- Click OK and exit out of the Style Editor.
- Select the Detail row for the getCustomerOrders table either from the Visual Designer or from the Outline.

- In the Property Editor, select General.
- In the Style list box, select detailAlternatingRowColor.

Now, when we run the report, we can see the detail row has the alternating colors we were looking for. We can easily apply this to any of the detail rows in our report.
Now let's move to the next method—applying Highlighting property directly to an element.
- Select the Detail row of the customer information table and remove the detailAlternatingRowColor style applied in the last two steps of the previous method.
- With the Detail row selected, use the Property Editor and select the Highlight tab.

- Click the Add… button.
- Set the Condition as row.__rownum % 2.
- Set the comparison operator to Equal to.
- Set the value to 0.
- Set the Background color to Silver.

- Click OK.
- Preview the report.

Just like with the previous example, we have an alternating row color in the detailssection. The only difference is where this is applied. In the first example it is applied as a style, whereas in the second it is applied to the detail row directly.
Summary
In this article we have demonstrated the various ways a report developer can format their report using basic formatting, styles and stylesheets,



Post new comment