帆软后台下载 main

package avicit;

import java.io.File;
import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;

import com.fr.base.FRContext;
import com.fr.dav.LocalEnv;
import com.fr.general.ModuleContext;
import com.fr.io.TemplateWorkBookIO;
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.PDFExporterProcessor;
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;
import com.fr.report.module.EngineModule;
import com.fr.stable.WriteActor;
import com.fr.web.core.reserve.PDFExporterFactory;

public class ExportApi {

public static void main(String[] args) {
	// 定义报表运行环境,才能执行报表
	//String envpath = request.getRealPath("WEB-INF");
	String envpath = "E:\\workSpace\\v6\\PlatformWebappPro\\src\\main\\webapp\\WEB-INF";
	FRContext.setCurrentEnv(new LocalEnv(envpath));
	ModuleContext.startModule(EngineModule.class.getName());

	ResultWorkBook rworkbook = null;
	try {
		// 未执行模板工作薄
		WorkBook workbook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), "\\test.cpt");
		// 获取报表参数并设置值,导出内置数据集时数据集会根据参数值查询出结果从而转为内置数据集
		int i = 1;
		while (i <= 3) {
			i++;
			// 定义parametermap用于执行报表,将执行后的结果工作薄保存为rworkBook
			java.util.Map parameterMap = new java.util.HashMap();

			parameterMap.put("mesEwoId", "");
			// 定义输出流
			FileOutputStream outputStream;
			// 将未执行模板工作薄导出为内置数据集模板
			outputStream = new FileOutputStream(new File("D:\\1\\EmbExport_"+i+".cpt"));
			EmbeddedTableDataExporter templateExporter = new EmbeddedTableDataExporter();
			templateExporter.export(outputStream, workbook);
			// 将模板工作薄导出模板文件,在导出前您可以编辑导入的模板工作薄,可参考报表调用章节
			outputStream = new FileOutputStream(new File("D:\\1\\TmpExport_"+i+".cpt"));
			((WorkBook) workbook).export(outputStream);
			// 将结果工作薄导出为2003Excel文件
			outputStream = new FileOutputStream(new File("D:\\1\\ExcelExport_"+i+".xls"));
			ExcelExporter ExcelExport = new ExcelExporter();
			ExcelExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
			// 将结果工作薄导出为Excel文件
			outputStream = new FileOutputStream(new File("D:\\1\\ExcelExport_"+i+".xlsx"));
			StreamExcel2007Exporter ExcelExport1 = new StreamExcel2007Exporter();
			ExcelExport1.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
			// 将结果工作薄导出为Word文件
			outputStream = new FileOutputStream(new File("D:\\1\\WordExport_"+i+".doc"));
			WordExporter WordExport = new WordExporter();
			WordExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
			// 将结果工作薄导出为Pdf文件
			outputStream = new FileOutputStream(new File("D:\\1\\PdfExport_"+i+".pdf"));
			PDFExporterProcessor PdfExport = PDFExporterFactory.getPDFExporter();
			PdfExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
			// 将结果工作薄导出为Txt文件(txt文件本身不支持表格、图表等,被导出模板一般为明细表)
			outputStream = new FileOutputStream(new File("D:\\1\\TxtExport_"+i+".txt"));
			TextExporter TxtExport = new TextExporter();
			TxtExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
			// 将结果工作薄导出为Csv文件
			outputStream = new FileOutputStream(new File("D:\\1\\CsvExport_"+i+".csv"));
			CSVExporter CsvExport = new CSVExporter();
			CsvExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
			// 将结果工作薄导出为SVG文件
			outputStream = new FileOutputStream(new File("D:\\1\\SvgExport_"+i+".svg"));
			SVGExporter SvgExport = new SVGExporter();
			SvgExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
			// 将结果工作薄导出为image文件
			outputStream = new FileOutputStream(new File("D:\\1\\PngExport_"+i+".png"));
			ImageExporter ImageExport = new ImageExporter();
			ImageExport.export(outputStream, workbook.execute(parameterMap, new WriteActor()));
			outputStream.close();
			ModuleContext.stopModules();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}

}

你可能感兴趣的:(帆软后台下载 main)