Jump to content
We've recently updated our Privacy Statement, available here ×

report templates


sgolestane

Recommended Posts

To eliminate duplication and provide consistance look and feel across all reports i've decided to  remove style defenitions from .jrxml files and define them in java and pass them to JasperPrint at run time as JRParameter.REPORT_TEMPLATES parameter.

reports can include sub reports.

I've bean successfull to do this for the main report but havn't found a way pass these templates to sub reports.

any suggestion?

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

OK i found a solution for this:

  1. Create a calss that implements net.sf.jasperreports.engine.JRTemplate and setup styles in that class. (see ACMETemplate)
  2. include this class as a template element in your jrxml file :<template class="net.sf.jasperreports.engine.JRTemplate"><![CDATA[new acme.jasper.ACMETemplate()]]></template>

doing this you can control style of all your reports in a single defenition class.

Code:
package acme.jasper;import java.awt.Color;import net.sf.jasperreports.engine.JRAlignment;import net.sf.jasperreports.engine.JRElement;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRSimpleTemplate;import net.sf.jasperreports.engine.design.JRDesignStyle;public class ACMETemplate extends JRSimpleTemplate{    public MarchexTemplate() throws JRException    {        super();        Color blue = new Color(123, 177, 208);        JRDesignStyle defultStyle = new JRDesignStyle();        defultStyle.setName("defult");        defultStyle.setDefault(true);        defultStyle.setFontName("Arial");        defultStyle.setFontSize(12);        defultStyle.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);        defultStyle.setMode(JRElement.MODE_OPAQUE);        addStyle(defultStyle);        JRDesignStyle tableTitleStyle = new JRDesignStyle();        tableTitleStyle.setParentStyle(defultStyle);        tableTitleStyle.setName("tableTitle");        tableTitleStyle.setBold(true);        addStyle(tableTitleStyle);        JRDesignStyle topHeaderStyle = new JRDesignStyle();        topHeaderStyle.setParentStyle(defultStyle);        topHeaderStyle.setName("topHeader");        topHeaderStyle.setBold(true);        topHeaderStyle.setBackcolor(blue);        topHeaderStyle.getLineBox().setLeftPadding(5);        topHeaderStyle.getLineBox().setRightPadding(5);        addStyle(topHeaderStyle);        JRDesignStyle cellStyle = new JRDesignStyle();        cellStyle.setParentStyle(defultStyle);        cellStyle.setName("cell");        cellStyle.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);        cellStyle.getLineBox().setLeftPadding(5);        cellStyle.getLineBox().setRightPadding(5);        cellStyle.getLineBox().getTopPen().setLineColor(blue);        cellStyle.getLineBox().getTopPen().setLineWidth(0);        cellStyle.getLineBox().getLeftPen().setLineColor(blue);        cellStyle.getLineBox().getLeftPen().setLineWidth(0.25F);        cellStyle.getLineBox().getBottomPen().setLineColor(blue);        cellStyle.getLineBox().getBottomPen().setLineWidth(0.25F);        cellStyle.getLineBox().getRightPen().setLineColor(blue);        cellStyle.getLineBox().getRightPen().setLineWidth(0.25F);        addStyle(cellStyle);        JRDesignStyle leftHeaderStyle = new JRDesignStyle();        leftHeaderStyle.setParentStyle(defultStyle);        leftHeaderStyle.setName("leftHeader");        leftHeaderStyle.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);        leftHeaderStyle.setBackcolor(Color.LIGHT_GRAY);        leftHeaderStyle.getLineBox().setLeftPadding(5);        addStyle(leftHeaderStyle);        JRDesignStyle leftAlignCellStyle = new JRDesignStyle();        leftAlignCellStyle.setParentStyle(defultStyle);        leftAlignCellStyle.setName("leftAlignCell");        leftAlignCellStyle.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);        addStyle(leftAlignCellStyle);    }}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...