Using a Java Report Streaming Class
What is a Java Report Streaming Class
A Java Report Streaming class is a java class that will run at the end of the Excel Report process, and will allow manipulating the XLSX file using Apache POI SXSSF (Streamed XSSF) API.
This allows inserting data in the template row by row with high performance and low memory consumption, at the expense of limiting the set of POI features available.
You can retrieve all the data available to the report from the Java code. You can also use the same database-related tools as in the Java Preprocessor class.
When to Use Java Report Streaming Class
A Java Report Streaming class, instead of Large Data Mode, should be used when one requires more advanced control on the style of data inserted, or needs to insert data on any spreadsheet of the workbook. It allows the same level of performance and memory usage as the Large Data Mode.
How to Use Java Report Streaming Class
Creating the Report Type
In the report type’s command steps, anywhere between the first
ksc_run_excel_report line and the last
ksc_end_report_parameters line, add the parameter
REPORT_STREAM_DATA_CLASS, with the value being the fully qualified class name of your Postprocessor class. For example , for the class
com.hpe.ppm.excelreports.SampleSteamingClass that you can find in the attached bundle in folder
7 - Using a Java report streaming class, the line would be:
Creating the Java Report Streaming Class
You should create a Java class that extends the existing abstract class
com.mercury.itg.common.excel.exporter.data.ExcelReportStreamData. The single method to implement is:
public void streamDataToWorkbook(SXSSFWorkbook wb).
You can then directly work on the passed SXSSF workbook object to modify the report XLSX document, but keep in mind that you can only add rows to the spreadsheets with this API.
For more information, you can refer to the sample streaming class
SampleStreamingClass.java located in the attached bundle (in the path
7 - Using a Java report streaming class\1 - Sample Report Streaming class source code\com\hpe\ppm\excelreports).
Deploying the Java Report Streaming Class
Deploy the Java Report Streaming class in the same way as you deploy a Preprocessor class. See Deploying the Java Preprocessor Class.
Creating the Excel Template
There is nothing special to do on the excel template if you are using a Java Report Streaming Class. Just ensure that there are no empty rows already written at the end of the sheets you want to modify. You can remove them first with a Java Report Postprocessor class.
Example of Report Using a Java Streaming Class
You can find an example of an Excel template and the resulting report in file
Samples\7 - Using a Java report streaming class. The source code and a jar version of the Java Streaming class are included.