You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.8 KiB
60 lines
2.8 KiB
6 years ago
|
package com.fr.io;
|
||
6 years ago
|
import com.fr.base.operator.common.CommonOperator;
|
||
|
import com.fr.chart.activator.ChartBaseActivator;
|
||
6 years ago
|
import com.fr.config.activator.BaseDBActivator;
|
||
|
import com.fr.config.activator.ConfigurationActivator;
|
||
|
import com.fr.data.impl.config.activator.RestrictionActivator;
|
||
6 years ago
|
import com.fr.env.operator.CommonOperatorImpl;
|
||
6 years ago
|
import com.fr.io.exporter.ExcelExporter;
|
||
|
import com.fr.main.TemplateWorkBook;
|
||
|
import com.fr.main.workbook.ResultWorkBook;
|
||
|
import com.fr.module.Module;
|
||
|
import com.fr.module.tool.ActivatorToolBox;
|
||
|
import com.fr.report.ReportActivator;
|
||
|
import com.fr.report.module.ReportBaseActivator;
|
||
|
import com.fr.stable.WriteActor;
|
||
|
import com.fr.store.StateServerActivator;
|
||
|
import com.fr.workspace.simple.SimpleWork;
|
||
|
import java.io.File;
|
||
|
import java.io.FileOutputStream;
|
||
|
|
||
|
|
||
|
public class ExcuteDemo {
|
||
|
public static void main(String[] args) {
|
||
|
try {
|
||
6 years ago
|
// 首先需要定义执行所在的环境,这样才能正确读取数据库信息
|
||
|
// 定义报表运行环境,用于执行报表
|
||
6 years ago
|
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(),
|
||
6 years ago
|
new ConfigurationActivator(),
|
||
|
new StateServerActivator(),
|
||
|
new ReportBaseActivator(),
|
||
|
new RestrictionActivator(),
|
||
6 years ago
|
new ReportActivator(),
|
||
|
new ChartBaseActivator());
|
||
|
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl());
|
||
|
String envpath= "//Applications//FineReport10_325//webapps//webroot//WEB-INF"; //工程路径
|
||
6 years ago
|
SimpleWork.checkIn(envpath);
|
||
|
module.start();
|
||
6 years ago
|
// 读取模板
|
||
|
TemplateWorkBook workbook = TemplateWorkBookIO.readTemplateWorkBook("//doc//Primary//Parameter//Parameter.cpt");
|
||
6 years ago
|
/*
|
||
|
* 生成参数map,注入参数与对应的值,用于执行报表 该模板中只有一个参数地区,给其赋值华北
|
||
|
* 若参数在发送请求时传过来,可以通过req.getParameter(name)获得
|
||
|
* 获得的参数put进map中,paraMap.put(paraname,paravalue)
|
||
|
*/
|
||
|
java.util.Map paraMap = new java.util.HashMap();
|
||
|
paraMap.put("地区", "华北");
|
||
6 years ago
|
// 使用paraMap执行生成结果
|
||
6 years ago
|
ResultWorkBook result = workbook.execute(paraMap, new WriteActor());
|
||
6 years ago
|
// 使用结果如导出至excel
|
||
6 years ago
|
FileOutputStream outputStream = new FileOutputStream(new File(
|
||
6 years ago
|
"//Users//susie//Downloads//Parameter.xls"));
|
||
6 years ago
|
ExcelExporter excelExporter = new ExcelExporter();
|
||
6 years ago
|
excelExporter.export(outputStream,result);
|
||
6 years ago
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
} finally {
|
||
|
SimpleWork.checkOut();
|
||
|
}
|
||
|
}
|
||
|
}
|