Home
DevShare Downloads
Set Font/Style information on a report using DE API or Script
JasonW
<p><span style=""font-size: xx-small;"">You can set style information using the DE API in the following ways</span></p>
<p><span style=""font-size: xx-small;"">You can set properties directly <br /> data = elementFactory.newDataItem( null ); <br /> data.setProperty( StyleHandle.FONT_FAMILY_PROP,""Arial""); <br /><br />or modify the default report style property <br />reportDesignHandle.findStyle(""report"").setProperty(StyleHandle.FONT_FAMILY_PROP, ""Arial""); <br /><br />or use a new style. To create a style use the ElementFactory like: <br /><br /> private void createStyles( ) throws SemanticException <br /> { <br /> StyleHandle labelStyle = elementFactory.newStyle( ""Label"" ); <br /> labelStyle.setProperty( StyleHandle.FONT_WEIGHT_PROP, <br /> DesignChoiceConstants.FONT_WEIGHT_BOLD ); <br /> labelStyle.setProperty( StyleHandle.FONT_FAMILY_PROP, ""Arial Black"" ); <br /> labelStyle.setProperty( StyleHandle.COLOR_PROP, ""#008000"" ); <br /><br /> StyleHandle dataStyle = elementFactory.newStyle( ""Data"" ); <br /> dataStyle.setProperty( StyleHandle.FONT_WEIGHT_PROP, <br /> DesignChoiceConstants.FONT_WEIGHT_BOLD ); <br /> dataStyle.setProperty( StyleHandle.FONT_FAMILY_PROP, ""Century"" );<br /> dataStyle.setProperty( StyleHandle.COLOR_PROP, ""#009B9B"" ); <br /><br /> reportDesignHandle.getStyles( ).add( labelStyle ); <br /> reportDesignHandle.getStyles( ).add( dataStyle ); <br /> } <br /><br />Then set the style on an element like: <br /><br /> CellHandle tcell = (CellHandle) header.getCells( ).get( 0 ); <br /> LabelHandle label = elementFactory.newLabel( null ); <br /> label.setText( ""Product"" ); <br /> label.setStyleName( ""Label"" ); <br /> tcell.getContent( ).add( label );</span></p>
<p><span style=""font-size: xx-small;"">You can also do this in the beforeFactory script of any report like:</span></p>
<p align=""left""> </p>
<p align=""left""> </p>
<p>
<p>
<p align=""left""><span style=""font-size: xx-small;"">importPackage(Packages.org.eclipse.birt.report.model.api);</span></p>
<p align=""left""><span style=""font-size: xx-small;"">importPackage(Packages.org.eclipse.birt.report.model.api.elements);</span></p>
<p align=""left""> </p>
<p align=""left""><span style=""font-size: xx-small;"">reportContext.getDesignHandle().findStyle(</span></p>
<span style=""font-size: xx-small;""><span style=""color: #2a00ff;""><span style=""color: #2a00ff;"">""report""</span></span>).setProperty(StyleHandle.FONT_FAMILY_PROP, <span style=""color: #2a00ff;""><span style=""color: #2a00ff;"">""Arial""</span></span></span>
<p align=""left""><span style=""font-size: xx-small;"">);</span></p>
<p align=""left""><span style=""font-size: xx-small;"">reportContext.getDesignHandle().findStyle(</span></p>
<span style=""font-size: xx-small;""><span style=""color: #2a00ff;""><span style=""color: #2a00ff;"">""report""</span></span>).setProperty( StyleHandle.COLOR_PROP, <span style=""color: #2a00ff;""><span style=""color: #2a00ff;"">""#009B9B""</span></span></span>
<p align=""left""><span style=""font-size: xx-small;""> );</span></p>
<p><span style=""font-size: xx-small;"">reportContext.getDesignHandle().findStyle(</span></p>
<span style=""color: #2a00ff;""><span style=""color: #2a00ff; font-size: xx-small;"">""report""</span></span>
<p><span style=""font-size: xx-small;"">).setProperty( StyleHandle.FONT_WEIGHT_PROP, DesignChoiceConstants.FONT_WEIGHT_BOLD );</span></p>
</p>
</p>
<p> </p>
<p> </p>
Find more posts tagged with
Comments
There are no comments yet