forked from demo/example
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.
111 lines
6.1 KiB
111 lines
6.1 KiB
7 years ago
|
package com.fr.io;
|
||
|
|
||
|
import com.fr.base.Parameter;
|
||
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;
|
||
7 years ago
|
import com.fr.general.ModuleContext;
|
||
|
import com.fr.io.exporter.CSVExporter;
|
||
|
import com.fr.io.exporter.EmbeddedTableDataExporter;
|
||
|
import com.fr.io.exporter.ExcelExporter;
|
||
|
import com.fr.io.exporter.ImageExporter;
|
||
|
import com.fr.io.exporter.PDFExporter;
|
||
|
import com.fr.io.exporter.SVGExporter;
|
||
|
import com.fr.io.exporter.TextExporter;
|
||
|
import com.fr.io.exporter.WordExporter;
|
||
|
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter;
|
||
|
import com.fr.main.impl.WorkBook;
|
||
|
import com.fr.main.workbook.ResultWorkBook;
|
||
6 years ago
|
import com.fr.module.Module;
|
||
|
import com.fr.module.tool.ActivatorToolBox;
|
||
|
import com.fr.report.ReportActivator;
|
||
|
import com.fr.report.module.ReportBaseActivator;
|
||
7 years ago
|
import com.fr.stable.WriteActor;
|
||
6 years ago
|
import com.fr.store.StateServerActivator;
|
||
7 years ago
|
import com.fr.workspace.simple.SimpleWork;
|
||
7 years ago
|
|
||
|
import java.io.File;
|
||
|
import java.io.FileOutputStream;
|
||
|
|
||
|
|
||
|
public class ExportApi {
|
||
|
public static void main(String[] args) {
|
||
6 years ago
|
// 定义报表运行环境,用于执行报表
|
||
6 years ago
|
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(),
|
||
6 years ago
|
new ConfigurationActivator(),
|
||
|
new StateServerActivator(),
|
||
|
new ReportBaseActivator(),
|
||
|
new RestrictionActivator(),
|
||
|
new ReportActivator(),
|
||
6 years ago
|
new ChartBaseActivator());
|
||
|
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl());
|
||
|
String envpath = "//Applications//FineReport10_325//webapps//webroot//WEB-INF";//工程路径
|
||
7 years ago
|
SimpleWork.checkIn(envpath);
|
||
6 years ago
|
module.start();
|
||
7 years ago
|
ResultWorkBook rworkbook = null;
|
||
|
try {
|
||
6 years ago
|
// 未执行模板工作薄
|
||
7 years ago
|
WorkBook workbook = (WorkBook) TemplateWorkBookIO
|
||
6 years ago
|
.readTemplateWorkBook("//doc//Primary//Parameter//Parameter.cpt");
|
||
|
// 获取报表参数并设置值,导出内置数据集时数据集会根据参数值查询出结果从而转为内置数据集
|
||
7 years ago
|
Parameter[] parameters = workbook.getParameters();
|
||
|
parameters[0].setValue("华东");
|
||
6 years ago
|
// 定义parametermap用于执行报表,将执行后的结果工作薄保存为rworkBook
|
||
7 years ago
|
java.util.Map parameterMap = new java.util.HashMap();
|
||
|
for (int i = 0; i < parameters.length; i++) {
|
||
|
parameterMap.put(parameters[i].getName(), parameters[i]
|
||
|
.getValue());
|
||
|
}
|
||
6 years ago
|
// 定义输出流
|
||
7 years ago
|
FileOutputStream outputStream;
|
||
6 years ago
|
// 将未执行模板工作薄导出为内置数据集模板
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//EmbExport.cpt"));
|
||
7 years ago
|
EmbeddedTableDataExporter templateExporter = new EmbeddedTableDataExporter();
|
||
|
templateExporter.export(outputStream, workbook);
|
||
6 years ago
|
// 将模板工作薄导出模板文件,在导出前您可以编辑导入的模板工作薄,可参考报表调用章节
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//TmpExport.cpt"));
|
||
7 years ago
|
((WorkBook) workbook).export(outputStream);
|
||
6 years ago
|
// 将结果工作薄导出为2003Excel文件
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//ExcelExport.xls"));
|
||
7 years ago
|
ExcelExporter ExcelExport = new ExcelExporter();
|
||
|
ExcelExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
|
||
6 years ago
|
// 将结果工作薄导出为Excel文件
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//ExcelExport.xlsx"));
|
||
7 years ago
|
StreamExcel2007Exporter ExcelExport1 = new StreamExcel2007Exporter();
|
||
|
ExcelExport1.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
|
||
6 years ago
|
// 将结果工作薄导出为Word文件
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//WordExport.doc"));
|
||
7 years ago
|
WordExporter WordExport = new WordExporter();
|
||
|
WordExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
|
||
6 years ago
|
// 将结果工作薄导出为Pdf文件
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//PdfExport.pdf"));
|
||
7 years ago
|
PDFExporter PdfExport = new PDFExporter();
|
||
|
PdfExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
|
||
6 years ago
|
// 将结果工作薄导出为Txt文件(txt文件本身不支持表格、图表等,被导出模板一般为明细表)
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//TxtExport.txt"));
|
||
7 years ago
|
TextExporter TxtExport = new TextExporter();
|
||
|
TxtExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
|
||
6 years ago
|
// 将结果工作薄导出为Csv文件
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//CsvExport.csv"));
|
||
7 years ago
|
CSVExporter CsvExport = new CSVExporter();
|
||
|
CsvExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
|
||
6 years ago
|
//将结果工作薄导出为SVG文件
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//SvgExport.svg"));
|
||
7 years ago
|
SVGExporter SvgExport = new SVGExporter();
|
||
|
SvgExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
|
||
6 years ago
|
//将结果工作薄导出为image文件
|
||
|
outputStream = new FileOutputStream(new File("/Users//susie//Downloads//PngExport.png"));
|
||
7 years ago
|
ImageExporter ImageExport = new ImageExporter();
|
||
|
ImageExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
|
||
|
outputStream.close();
|
||
6 years ago
|
module.stop();
|
||
7 years ago
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
7 years ago
|
} finally {
|
||
|
SimpleWork.checkOut();
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|