Class ExcelReport

java.lang.Object
ca.spatial.reportwriter.Report
ca.spatial.reportwriter.ExcelReport
All Implemented Interfaces:
Selectable<Report>, Comparable<Report>

public class ExcelReport extends Report
This report allows customization of an Excel workbook. Processing is done in a custom method that must be passed in as an ExcelReportProcessor object. The processor uses the Apache POI XSSF usermodel API to manipulate the workbook contents.

If a template is specified the template will be opened and loaded prior to calling the converter. The template is not changed. If the template argument is null then an empty workbook will be provided to the processor.

Example

This example loads a template xlsx file. The processor script makes changes to the existing sheet and cell values. Note that the processor script is passed references to the workbook and the ReportWriter parameters.

 ExcelReportProcessor valueHandler() {
    public void processWorkbook(XSSFWorkbook workbook, Map param) {

       // Get the sheet named "Values"
       sh = workbook.getSheet("Values");

       // Get the scenario name and store it into cell A1
       // Note that row and column numbering starts at zero
       name = param.get("scenario");
       if (name != null)
          sh.getRow(0).getCell(0).setCellValue(name);

       // Store a number in to cell B2
       sh.getRow(1).getCell(1).setCellValue(23);

    }

    // return the reference to this processor object
    return this;
 }

 report1 = new ExcelReport("valueSpreadsheet.xlsx",
                           "Value spreadsheet",
                           "../misc/ValueSpreadsheet_Template.xlsx",
                           valueHandler());
 reportWriter.addReport(report1);
 
  • Field Details

    • TYPES

      public static final String[] TYPES
      This field describes the multiple renderings that are supported by the report. In this case no multiple renderings are supported.
  • Constructor Details

    • ExcelReport

      public ExcelReport(String filename, String title, String template, ExcelReportProcessor processor)
      Parameters:
      filename - The filename that the report will be saved as
      title - The title to display in the table of contents
      template - A template file that is used to initialize the working document. If specified the template is loaded but not changed. If null then the initial workbook will be empty.
      processor - A reference to an ExcelReportProcessor processor object that will do the customization.
  • Method Details

    • getTemplate

      public String getTemplate()
      Get the current template file
    • setTemplate

      public void setTemplate(String template)
      Set the template file
    • getProcessor

      public ExcelReportProcessor getProcessor()
      Get the current processor object
    • setProcessor

      public void setProcessor(ExcelReportProcessor processor)
      Set the processor object
    • doReport

      public ca.spatial.reportwriter.Report.DataCache doReport(String filename, PrintStream out, Map<String,​Object> param, ca.spatial.reportwriter.Report.DataCache cache)
      Description copied from class: Report
      The method used by the report writer to format the requested report. This method is implemented in every custom report. Application programs generally do not need to call this method, but instead use the report writer methods to obtain reports.
      Specified by:
      doReport in class Report
      Parameters:
      filename - The full name of the report to be printed, including the extension of the sub-report (if any).
      out - The output stream to print output on to.
      param - A HashMap containing parameters that modify the report (for example the scenario name).
    • getTypes

      public String[] getTypes()
      Description copied from class: Report
      An accessor function to retrieve the list of report types supported by this report. See the documentation for the TYPES variable for the list of sub-types.
      Specified by:
      getTypes in class Report