I. Overview
1. Scenario
The computed result of a report can be variable in different conditions. To save the results of each condition, such as save them into an Excel file, you can carry it out in bulk by invoking the export interface ExcelExporter.
2. Approaches
To batch export the results into Excel with codes, the first thing to do is to traverse and load each set of parameter values in para.txt, and pass the acquired values into the template for calculation. Then, export the calculated data into an Excel file, looping until the end of the last parameter group is reached.
II. Instructions
The article takes %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc\Primary\Parameter\Parameter.cpt as an example to perform batch export into Excel files in the background.
1. Parameter Group
Due to the fact that different parameter groups can bring out different results, it's necessary to obtain all the possible parameter values, which can be derived from a certain table in a database or a file.
Save the group of parameter values in a text file, such as para.text. Place it into %FR_HOME%\webapps\webroot\WEB-INF\ and ensure the content is formatted as below:
The case of only one parameter:
For two parameters, use commas to separate two values as follows:
2. The Batch Export Program
Please go to the following URL for the complete codes: https://github.com/finereport-overseas/example/blob/release/10.0/src/main/java/com/fr/io/ExportBatch.java
Note 1: some JARs need to be imported when using APIs to export as different types of files. Please see below.
FineReport Default JARs
sqlite-jdbc.jar under the directory of %FR_HOME%\webroot\WEB-INF\lib
serverlet-api.jar under the directory of %Tomcat_HOME%\lib
tools.jar under the directory of %JAVA_HOME%\jdk\lib
Note 2: when an exported Excel file contains nothing but the format of its template, please confirm whether the above codes for defining the reporting environment are correct or available. Otherwise, the above "no data" issue will occur.
The aforesaid codes are for reference only. Don't forget to modify those variables, such as report runtime environment and the template name, based on your practical situation.
Startup the designer. Once the program is successfully compiled and run, two Excel files will be brought to the download directory.