java代码导出word如果报错给出提示_导出API- FineReport帮助文档|报表开发|报表使用|学习教程...

package com.fr.io;

import java.io.File;

import java.io.FileOutputStream;

import com.fr.base.FRContext;

import com.fr.general.ModuleContext;

import com.fr.base.Parameter;

import com.fr.dav.LocalEnv;

import com.fr.io.exporter.CSVExporter;

import com.fr.io.exporter.EmbeddedTableDataExporter;

import com.fr.io.exporter.ExcelExporter;

import com.fr.io.exporter.PDFExporter;

import com.fr.io.exporter.PDFExporterProcessor;

import com.fr.io.exporter.TextExporter;

import com.fr.io.exporter.WordExporter;

import com.fr.io.exporter.SVGExporter;

import com.fr.io.exporter.ImageExporter;

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 = "E:\\FineReport_9.0\\WebReport\\WEB-INF";

FRContext.setCurrentEnv(new LocalEnv(envpath));

ModuleContext.startModule(EngineModule.class.getName());

ResultWorkBook rworkbook = null;

try {

// 未执行模板工作薄

WorkBook workbook = (WorkBook) TemplateWorkBookIO

.readTemplateWorkBook(FRContext.getCurrentEnv(),

"\\doc\\Primary\\Parameter\\Parameter.cpt");

// 获取报表参数并设置值,导出内置数据集时数据集会根据参数值查询出结果从而转为内置数据集

Parameter[] parameters = workbook.getParameters();

parameters[0].setValue("华东");

// 定义parametermap用于执行报表,将执行后的结果工作薄保存为rworkBook

java.util.Map parameterMap = new java.util.HashMap();

for (int i = 0; i < parameters.length; i++) {

parameterMap.put(parameters[i].getName(), parameters[i]

.getValue());

}

// 定义输出流

FileOutputStream outputStream;

// 将未执行模板工作薄导出为内置数据集模板

outputStream = new FileOutputStream(new File("D:\\EmbExport.cpt"));

EmbeddedTableDataExporter templateExporter = new EmbeddedTableDataExporter();

templateExporter.export(outputStream, workbook);

// 将模板工作薄导出模板文件,在导出前您可以编辑导入的模板工作薄,可参考报表调用章节

outputStream = new FileOutputStream(new File("D:\\TmpExport.cpt"));

((WorkBook) workbook).export(outputStream);

// 将结果工作薄导出为2003Excel文件

outputStream = new FileOutputStream(new File("D:\\ExcelExport.xls"));

ExcelExporter ExcelExport = new ExcelExporter();

ExcelExport.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

// 将结果工作薄导出为Excel文件

outputStream = new FileOutputStream(new File("D:\\ExcelExport.xlsx"));

StreamExcel2007Exporter ExcelExport1 = new StreamExcel2007Exporter();

ExcelExport1.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

// 将结果工作薄导出为Word文件

outputStream = new FileOutputStream(new File("D:\\WordExport.doc"));

WordExporter WordExport = new WordExporter();

WordExport.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

// 将结果工作薄导出为Pdf文件

outputStream = new FileOutputStream(new File("D:\\PdfExport.pdf"));

PDFExporterProcessor PdfExport = PDFExporterFactory.getPDFExporter();

PdfExport.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

// 将结果工作薄导出为Txt文件(txt文件本身不支持表格、图表等,被导出模板一般为明细表)

outputStream = new FileOutputStream(new File("D:\\TxtExport.txt"));

TextExporter TxtExport = new TextExporter();

TxtExport.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

// 将结果工作薄导出为Csv文件

outputStream = new FileOutputStream(new File("D:\\CsvExport.csv"));

CSVExporter CsvExport = new CSVExporter();

CsvExport.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

//将结果工作薄导出为SVG文件

outputStream = new FileOutputStream(new File("D:\\SvgExport.svg"));

SVGExporter SvgExport = new SVGExporter();

SvgExport.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

//将结果工作薄导出为image文件

outputStream = new FileOutputStream(new File("D:\\PngExport.png"));

ImageExporter ImageExport = new ImageExporter();

ImageExport.setSuffix("png");

ImageExport.export(outputStream, workbook.execute(parameterMap,new WriteActor()));

outputStream.close();

ModuleContext.stopModules();

} catch (Exception e) {

e.printStackTrace();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值