Use a Java report postprocessor
This topic introduces how to use a Java report postprocessor to generate Excel reports.
What is a Java report postprocessor
A Java report postprocessor is a java class that runs right after the Excel template is filled with data. It enables you to use the Apache POI XSSF API to edit the XLSX file, such as modify charts and add pictures.
You can retrieve all the data available to the report from the Java code, and add more data that will be available to the Java report streaming class. You can also use the same database-related tools as in the Java preprocessor class.
When to use Java report postprocessor
A Java report postprocessor can be used when complex operations are required on the XLSX file, and when adding these operations as script in the template presents a maintenance challenge.
However, a Java report postprocessor is not necessary if you use the large data mode to just insert large amounts of data in the document, as the report postprocessor requires loading the whole document to memory for processing.
How to use Java report postprocessor
Follow the steps below to use a Java report postprocessor to generate Excel reports.
Create a report type
In the report type’s command steps, anywhere between the first line
ksc_run_excel_report and the last line
ksc_end_report_parameters, add the
REPORT_POSTPROCESSOR_CLASS parameter. Set the parameter value to the fully qualified class name of your Postprocessor class. For example, for the class
com.hpe.ppm.excelreports.SamplePostProcessorClass that you can find in the attached bundle in the folder
6 - Using a Java report post-processor, the line would be:
Create a Java report postprocessor class
You should create a Java class that extends the existing abstract class
com.mercury.itg.common.excel.exporter.data.ExcelReportWorkbookPostprocessor. The single method to implement is:
public void processWorkbook(XSSFWorkbook wb)
You can then directly work on the passed XSSF workbook object to modify the report XLSX document.
For more information, see the sample postprocessor class
SamplePostProcessorClass.java located in the attached bundle (in the path
6 - Using a Java report post-processor\1 - Sample Report PostProcessor source code\com\hpe\ppm\excelreports ).
Deploy the Java report postprocessor class
Deploy the Java Report Postprocessor class in the same way as you deploy a Preprocessor class. See Deploy the Java preprocessor class.
Create the Excel template
There is nothing special to do on the excel template if you use a Java Report Postprocessor. The only limitation is that you cannot fill the template using the large data mode.
Example of report using a Postprocessor
You can find an example of an Excel template and the resulting report in the
Samples\6 - Using a Java report post-processor file. The source code and a jar version of the Java Postprocessor are included.