Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External Styles in JasperReports

Tags:

I'm working on a system that includes a large number of reports, generated using JasperReports. One of the newer features is that you can define styles for reports.

From the available docs I believe there is some way to have an external file defining styles to use, and you can reference that in your jasper reports. This allows a single style to be used by multiple reports.

I can't find any concrete information on whether this is an actual feature, and if it is, how to use it. Does anyone know if it is possible to have external styles for jasper reports, and if so, how to do it?

like image 881
Jamie Love Avatar asked Oct 13 '08 03:10

Jamie Love


People also ask

How do I add a style to Jasper report?

Open a report, right click on the Styles node into the Outline View and select "Create Style Template". Now a new dialog will be opened and from here you can select a style template created before. Select the style and hit Ok.

What language does jaspersoft use?

The default expression language is Java, but if you are not a programmer, we recommend that you design your projects with JavaScript or Groovy because those languages hide a lot of the Java complexity.

What is the difference between Jasper and Jrxml?

jrxml is a human readable XML file that contains the report template i.e. report structure and its formatting rules. . jasper is the compiled report template i.e. compiled . jrxml file.

What is subreport in Jasper report?

A subreport is a report included inside another report. This allows the creation of very complex layouts with different portions of a single document filled using different data sources and reports.


1 Answers

Use JasperReport templates. A JasperReports template is one that ends in .jrtx, and may look similar to this (styles.jrtx):

<?xml version="1.0"?> <!DOCTYPE jasperTemplate   PUBLIC "-//JasperReports//DTD Template//EN"   "http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">  <jasperTemplate>     <style name="Report Title" isDefault="false" hAlign="Center" fontSize="24" isBold="true"/>     <style name="Heading 1" isDefault="false" fontSize="18" isBold="true"/>     <style name="Heading 2" isDefault="false" fontSize="14" isBold="true"/> </jasperTemplate> 

and then in your .jrxml file, include it as a template:

... <template><![CDATA["styles.jrtx"]]></template> ... 

iReport also understands this, so your styles are imported and shown in iReport correctly (though I did notice sometimes it wouldn't pick them up an a reload or recompile was necessary).

like image 109
Jamie Love Avatar answered Oct 15 '22 15:10

Jamie Love