Programming using the BIRT Reporting APIs : Generating reports from an application : Preparing to render a formatted report : How to configure properties for a report in HTML format
 
How to configure properties for a report in HTML format
The code sample in Listing 12‑11 shows the use of rendering options on an IRunAndRenderTask object to set report parameter values, the output format of the report, and the output file name. The variable, engine, is a ReportEngine object. The variable, runnable, is an object of type IReportRunnable. The variable, name, is the name of the report design.
Listing 12‑11 Configuring properties on an IRunAndRenderTask object
// Create a run and render task object.
IRunAndRenderTask task = engine.createRunAndRenderTask( runnable );
// Set values for all parameters in a HashMap, parameterValues
task.setParameterValues( parameterValues );
// Validate parameter values.
boolean parametersAreGood = task.validateParameters( );
// Set the name of an output file and other HTML options.
HTMLRenderOption options = new HTMLRenderOption( );
String output = name.replaceFirst( ".rptdesign", ".html" );
options.setOutputFileName( output );
options.setImageDirectory( "image" );
options.setEmbeddable( false );
// Apply the rendering options to the task.
task.setRenderOption( options );
Understanding Excel rendering options
The EXCELRenderOption class provides the following methods to modify the appearance of the generated spreadsheet:
*setHideGridlines( ) uses a boolean value of true or false to hide or show gridlines in the spreadsheet.
*setOfficeVersion( ) sets the compatibility level of the spreadsheet. Valid values for the String parameter are office2003 and office2007. The default value is office2003.
*setWrappingText( ) uses a boolean value of true or false to set or unset text wrapping in cells in the spreadsheet.
The EXCELRenderOption class provides equivalent getter methods to retrieve the current values of the options.
Using generic methods to access rendering options
The RenderOption class provides getter and setter methods for accessing the most commonly used rendering options. For example, this class provides the getOutputFileName( ) and setOutputFileName( ) methods to get and set the file name of rendered report. RenderOption also provides fields to identify the options. An application accesses the less commonly used options by calling the following generic methods, inherited from TaskOption, using a RenderOption field as an argument:
*getOption( )
This method returns an Object containing the option value. For boolean or int values, the returned Object is a Boolean or Integer respectively.
*getBooleanOption( ), getIntOption( ), getStringOption( )
Use these methods if the code is accessing an option of known type. These methods return a boolean value, an int value, and a String object respectively.
*getOptions( )
This method returns a Hashmap object containing all the rendering options that have been set explicitly using setOption( ).
*hasOption( )
Use this method to check whether the rendering options object supports a particular option. If the object supports an option, this method returns true even if the value of the option is null.
*setOption( )
This method takes a second argument, an Object that contains the value of the option. For boolean or int values, use a Boolean or Integer object respectively.
The code sample in Listing 12‑12 provides examples of these methods.
Listing 12‑12 Using generic rendering options
RenderOption ro = new RenderOption( );
if ( ro.getOption( RenderOption.RENDER_DPI ) == null )
{
ro.setOption( RenderOption.RENDER_DPI, new Integer( 96 ) );
}
ro.setOption( RenderOption.RTL_FLAG, new Boolean( true ) );
 
// The following line returns:
// INFO: Options: {RenderDpi=96, RTLFlag=true}
logger.log( Level.INFO, "Options: " + ro.getOptions().toString());