Package ca.spatial.reportwriter
Class ExcelReport
java.lang.Object
ca.spatial.reportwriter.Report
ca.spatial.reportwriter.ExcelReport
- All Implemented Interfaces:
Selectable<Report>
,Comparable<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 theReportWriter
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);
-
Nested Class Summary
Nested classes/interfaces inherited from class ca.spatial.reportwriter.Report
Report.GetNodesAt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic String[]
This field describes the multiple renderings that are supported by the report.Fields inherited from class ca.spatial.reportwriter.Report
AREA, LINE, PIE, SIDE_BY_SIDE_BARS, STACKED_BARS
-
Constructor Summary
ConstructorsConstructorDescriptionExcelReport(String filename, String title, String template, ExcelReportProcessor processor)
-
Method Summary
Modifier and TypeMethodDescriptionca.spatial.reportwriter.Report.DataCache
doReport(String filename, PrintStream out, Map<String,Object> param, ca.spatial.reportwriter.Report.DataCache cache)
The method used by the report writer to format the requested report.Get the current processor objectGet the current template fileString[]
getTypes()
An accessor function to retrieve the list of report types supported by this report.void
setProcessor(ExcelReportProcessor processor)
Set the processor objectvoid
setTemplate(String template)
Set the template fileMethods inherited from class ca.spatial.reportwriter.Report
addDefaultParam, chartImg, compareTo, csvLink, doesAnyTypes, doesCSV, doesGIF, doesHTML, doesPNG, doesType, encodeFileURL, encodeURL, endMainContent, escapeRegexChars, footer, formatColumnHeadings, formatColumnHeadings, getAdditionalFiles, getAttributeStore, getBasepart, getBasepart, getDefaultFilename, getDisplayFormat, getExtension, getExtension, getFilename, getFolderpart, getFolderpart, getLength, getNamepart, getNamepart, getPathToRoot, getReportFor, getTitle, header, htmlText, indexLink, interpolateParams, isDhandler, isIndexed, isSelected, parentIndex, patternToRegex, setAttributeStore, setDefaultParams, setDisplayFormat, setIndexed, setSelected, setTitle, toString, uniqueLabels
-
Field Details
-
TYPES
This field describes the multiple renderings that are supported by the report. In this case no multiple renderings are supported.
-
-
Constructor Details
-
ExcelReport
- Parameters:
filename
- The filename that the report will be saved astitle
- The title to display in the table of contentstemplate
- 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 anExcelReportProcessor
processor object that will do the customization.
-
-
Method Details
-
getTemplate
Get the current template file -
setTemplate
Set the template file -
getProcessor
Get the current processor object -
setProcessor
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. -
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.
-