没有合适的资源?快使用搜索试试~ 我知道了~
首页使用FineReport报表二次开发详述
资源详情
资源评论
资源推荐
FineReport------报表技术领跑者
帆软(中国)有限公司
商务咨询电话:86-025-5186 2240
商务咨询邮箱:business@finereport.com
公司网址:http://www.finereport.com
1
使用 FineReport 报表二次开发详述
在大多数情况下 FineReport 都可以完全满足用户制作各种报表的需求,但是为了能够满足
个别用户的个性化需求,F ineReport 提供了丰富二次开发接口,方便用户将 FineReport 和自
己的项目实现无缝结合,用户在进行二次开发的工程中可以更加深入的体会到 FineReport 工具
的强大功能。
例如:在一些特殊领域,可能需要一些特殊的函数。或者要将某个模板文件通过指定的打印
机打印等等。
FineReport------报表技术领跑者
帆软(中国)有限公司
商务咨询电话:86-025-5186 2240
商务咨询邮箱:business@finereport.com
公司网址:http://www.finereport.com
2
目录
Report 的输入输出„„„„„„„„„„„„„„„„„„„„„„ 3
单元格格式设置„„„„„„„„„„„„„„„„„„„„„„„„ 7
将模板通过指定打印机打印„„„„„„„„„„„„„„„„„„„ 10
自定义函数„„„„„„„„„„„„„„„„„„„„„„„„„„ 12
URL 传递参数„„„„„„„„„„„„„„„„„„„„„„„„ 22
向报表中添加单元格„„„„„„„„„„„„„„„„„„„„„„25
读取单元格内容„„„„„„„„„„„„„„„„„„„„„„„„29
创建程序网络模版„„„„„„„„„„„„„„„„„„„„„„„32
读取模板报表„„„„„„„„„„„„„„„„„„„„„„„„„36
FineReport------报表技术领跑者
帆软(中国)有限公司
商务咨询电话:86-025-5186 2240
商务咨询邮箱:business@finereport.com
公司网址:http://www.finereport.com
3
Report 的输入输出
FineReport 提供了强大的输入输出功能,所有的这些输入输出的类都在 com.f r.report.io
包里面。Report 的输入指从报表的模板文件(XML 格式的)创建 Report 对象,输出指将 Report
保存为模板文件,F ineReport 还支持将 Report 保存为 PDF,Excel,Word,SVG,HTML,CSV
等文件格式。
读取模板文件
保存成模板文件
输出成 PDF 文件
输出成 Word 文件
输出成 Excel 文件
输出成文本文件
可执行代码
读取模板文件
// 读取模板
File cptFile = new File("D:\\stuff.cpt");
TemplateImporter templateImporter = new TemplateImporter();
WorkBook workBook = (WorkBook)templateImporter.generate(cptFile);
Stuff.cpt 是用报表设计器生成的模板文件。只需要用建立一个 TemplateImporter 对象,
然后调用它的 generateReport()方法来产生一个 Report 对象,同时可以将产生的 Report 对
象强制转换成 WorkSheet 或者 GroupReport。
保存成模板文件
// CPT
// 清空公式计算结果
E:\\newtemplate\\stuff.cpt这个是导出后新文档生成的地址
ReportHelper.clearFormulaResul t(workBook);
outputStream = new FileOutputStream(new
File("E:\\newtemplate\\stuff.cpt"));
FineReport------报表技术领跑者
帆软(中国)有限公司
商务咨询电话:86-025-5186 2240
商务咨询邮箱:business@finereport.com
公司网址:http://www.finereport.com
4
TemplateExporter templateExporter = new TemplateExporter();
templateExporter.export(outputStream,workBook.execute(paramet
erMap)) ;
通过调用 TemplateExporter 的 export Report(...)方法, 可以把 Report 对象以 CPT 格
式保存到外部磁盘文件当中。
可执行代码
读取报表模板 stuff.cpt,再分别保存为 stuff.cpt,stuff.pdf 和 stuff.xls。
package com.fr.demo;
import java.io.File;
import java.io.FileOutputStream;
import com.fr.base.FRContext;
import com.fr.base.dav.LocalEnv;
import com.fr.report.WorkBook;
import com.fr.report.core.ReportHelper;
import com.fr.report.io.ExcelExporter;
import com.fr.report.io.PDFExporter;
import com.fr.report.io.TemplateExporter;
import com.fr.report.io.TemplateImporter;
import com.fr.report.io.TextExporter;
import com.fr.report.io.WordExporter;
/**
* 演示如何导入导出模板
* @author edgar duan
* @version 6.5
FineReport------报表技术领跑者
帆软(中国)有限公司
商务咨询电话:86-025-5186 2240
商务咨询邮箱:business@finereport.com
公司网址:http://www.finereport.com
5
*/
public class ReportIO {
/**
* @param args
*/
public static void main(String[] args) {
// 报表运行环境路径, WEB-INF 目录所放的位置
String envPath = "C:/FineReport6.5/WebReport /WEB-INF ";
// 设置当前报表运行环境, 报表预览时需要一个运行环境
// 没有 WEB-INF 目录时, 路径设置为 null. FRContext.setCurrentEnv(new
LocalEnv(null));
FRContext.setCurrentEnv(new LocalEnv(envPath));
try {
// 读取模板
File cptFile = new File("D:\\stuff.cpt");
TemplateImporter templateImporter = new TemplateImporter();
WorkBook workBook =
(WorkBook)templateImporter.generate(cptFile);
java.util.Map parameterMap = new java.util.HashMap();
FileOutputStream outputStream;
//生成 CPT
// 清空公式计算结果
ReportHelper.clearFormulaResult(workBook);
outputStream = new FileOutputStream(new File("E:\\newtemplate\\stuff.cpt"));
TemplateExporter templateExporter = new TemplateExporter();
templateExporter.export(outputStream,
workBook.execute(parameterMap)) ;
//生成 PDF
ReportHelper.clearFormulaResult(workBook);
剩余37页未读,继续阅读
破Feel
- 粉丝: 9
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1