Stylesheets with Pentaho Report DesignerStylesheets are the second big feature being integrated into PRD this year (the other one being crosstabs). I submitted a feature request for stylesheets some months ago (PRD-3823, PRD3834), simply because working on big projects requires stylesheets: You don’t want to waste hours changing every single report in case your client wants to have a style amended; you don’t want to recreate styles over and over again when you create new reports etc. I did not expect this feature to arrive anytime soon, so, quite surprisingly, as of today they are available in the latest trunk snapshot even with full CSS3 support (download here) (posted by Thomas here)! My very simple sample report can be downloaded here.
It is possible to store styles internally or externally. External stylesheets will have the extension .prptstyle.
To me stylesheets are an import part of report design and I am sure many other users will welcome this new feature. So let’s have a look at how to create and use stylesheets in PRD:
Once you have the trunk snapshot downloaded (note: do not use for production!) open PRD and create a new report, add a query and a few fields:
How to create internal stylesIf you want to use internal styles, choose Format > Edit Style Definition.
This option is only useful when you intend to create a specific design for one specific report. I highly recommend you make use of an external stylesheet for bigger projects, which we will discuss next.
How to create an external stylesheetIn this case we want to create an external stylesheet, choose Window > Style Definition Editor.
Make sure you save the external stylesheet straight away and while you are working:
Add a new style rule:
Note: The name of the style-rule is very important, it’s not just an arbitrary name!
|Style Rule Name||Explanation|
|label[name="title"]||The style will be automatically applied to all labels with the name title. The title for the label element can be defined in the Attributes pane:|
|group-header label[name="title"]||This style will only be applied to a label with the name title in the group header.|
|report-header band[name=”subtitle”] label||This style will only be applied to a label which is located in the band of the subtitle.|
|details-header label||This style will be applied to all labels in the details header|
|itemband text-field||This style will be applied to all text fields in the details band|
|number-field[field="Sales"]||This style will be applied to all number-fields which represent the data field Sales:|
|#header||This CSS id selector style (more info here) will be applied to a unique element with the id in the Attributes pane set to ‘header’:
Note: Do not prefix the id with a # in the attribute value!
|.center||This CSS class selector style (more info here) will be applied to multiple elements which have the style-class in the Attributes pane set to center:
Note: You must not prefix center with a dot in the attribute value!
|.label.center||This CSS class selector style (more info here) will be applied to multiple elements which have the style-class in the Attributes pane set to center and are labels. |
Note: The attribute value has to be set to only “center”!
|report-footer label.notice||This style will be applied to the label element with the class attribute set to notice in the report footer.|
As you can see, the style rule name is a combination of various components.
Please find below a list of important report bands:
Important report elements:
How to reference an external stylesheetIn the Structure pane select Master Report.
In the Attributes pane click the select button for the style-sheet-reference:
Click the Select button again:
Next set the Filter to Resources and then select your stylesheet. Click OK:
How to assign styles to elementsOnly if you used CSS class and id selector compliant style rule names, you must specify them
respectively in the style-class and id attributes in the Attributes pane.
Specifying a class:
Specifying an id:
Note: Only specify the name without the dot or hash prefix!
Here a report with various styles applied (not only id and class selectors):
Working with the stylesheet XML fileIf you know what you are doing, you can directly open the *.prptstyle file in your favourite text editor and amend it there:
Note: You must be familiar with XML and must understand the structure of the stylesheet. This practice is not recommended for anyone not familiar with it.