I. Introduction
As we know from the overview of Engine API, reports can be classified into two categories, that is, the template and the result.
The template here refers to workbooks or reports that are not executed, with datasets concluded, data columns unexpanded and formulas not calculated yet.
The result comes into being once the execution is performed. At this point, data columns have been expanded in the result, where datasets are no longer stored.
Please see the diagram below:
Once the template receives parameter values, a result will be generated. The rest of the article will illustrate on how to implement this procedure step by step.
II. Principle
1. Report Runtime Environment
The first and foremost thing is to define the environment where the execution happens, so that the database information can be accessed and loaded correctly.
String envpath = "C:\\FineReport_10.0\\webapps\\webroot\\WEB-INF";
//The project path
SimpleWork.checkIn(envpath);
module.start();
2. Load the Template
TemplateWorkBook workbook = TemplateWorkBookIO.readTemplateWorkBook("\\doc\\Primary\\Parameter\\Parameter.cpt");
3. Inject the Parameter Value
/*
* Define paraMap and inject the parameter from the template as well as its corresponding value, that is, "region" and "Northern China" in this case
* If the parameter is passed over when the request is being sent, use req.getParameter(name) to acquire it
* Put the acquired parameter into paraMap.put(paraname,paravalue)
*/
java.util.Map paraMap = new java.util.HashMap();
paraMap.put("region", "Northern China");
// Use paraMap to generate the result
ResultWorkBook result = workbook.execute(paraMap, new WriteActor());
4. Use the Result (Export to Excel)
For the generated result, users can perform a variety of operations, such as export to Excel or PDF files. Please refer to export API for further information.
FileOutputStream outputStream = new FileOutputStream(new File(
"C:\\test\\Parameter.xls"));
ExcelExporter excelExporter = new ExcelExporter();
excelExporter.export(outputStream, result)