Output as Excel (Java)

Set up and configure output to Microsoft® Excel™ from your reporting application. This option is useful if you want to perform custom calculations in Excel.

Note: Excel reports, as output from Genero Report Writer, do not print at high quality. If you require high-fidelity printing, use one of the other output options, such as SVG.
To use any of the renderer classes, you must import the com.fourjs.report.runtime package:
import com.fourjs.report.runtime.*;

You can then use methods from the ExcelRenderer class to configure your Excel output.

Example

This code snippet shows some of the methods available for an object of the ExcelRenderer class:
// code snippet starts

String designFile = "OrderReport.4rp";

FormatHandler handler = new FormatWriter(outputFilename);
ExcelRenderer renderer = new ExcelRenderer(handler);

//configuring Excel output
renderer.setMergeCells(false);
renderer.setMergePages(true);
renderer.setOutputFormat(ExcelRenderer.OutputFormat.XLSX);

FourRpLayouter report = new FourRpLayouter(designFile, renderer);
        //Run the report 
report.setDebugLevel(9);

// some code omitted - view full source in demo

report.runFromJAXBObject(data);
    
// open the generated file:
File result = new File(outputFilename);
Desktop desktop = Desktop.getDesktop();
desktop.open(result);

// code snippet ends
In this example:
  • A FormatHandler object named handler is defined using the FormatWriter class, taking the name of the output file as its input.
  • The setMergeCells() method, when set to true, activates cell merging when the content spans several cells; when set to false, separate empty cells are created.
  • The setMergePages() method, when set to true, activates page merging; when set to false, separate sheets for each page are created.
  • The setOutputFormat() method sets the output format as determined by the argument. When set to ExcelRenderer.OutputFormat.XLSX, the format is output as XLSX format (for Microsoft Excel starting with version 2007).

For the full list of methods for this renderer class, refer to the Genero Report Writer Java API documentation.