77范文网 - 专业文章范例文档资料分享平台

FineReport报表软件API源代码之程序数据集、自定义函数和导出API(4)

来源:网络收集 时间:1970-01-01 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

1. 在eclipse中导入第三方包barcode4j-light.jar,并新建一个类UPCCODE,具体代码如下:

package com.fr.report.script.function;

import java.awt.image.BufferedImage;

import org.krysalis.barcode4j.impl.upcean.UPCABean;

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; import org.krysalis.barcode4j.tools.UnitConv;

import com.fr.report.script.NormalFunction;

public class UPCCode extends NormalFunction{ public Object run(Object[] args) {

if(args == null || args.length < 1) { return \参数不对,必须有一个参数\; } try {

UPCABean bean = new UPCABean();

final int dpi = Integer.parseInt(args[1].toString());

bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); // makes the narrow

bean.doQuietZone(false);

BitmapCanvasProvider canvas = new BitmapCanvasProvider(dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);

// Generate the barcode

bean.generateBarcode(canvas, \ + args[0]); // Signal end of generation canvas.finish(); // return image

return canvas.getBufferedImage(); } catch (Exception e) { e.printStackTrace(); }

return args[0]; } }

2. 将编译后的UPCCODE.class文件放在报表环境目录\\WebReport\\WEB-INF\\lib\\ fr-server-6.5.jar\\com\\fr\\report\\script\\function下

3. 将第三方包barcode4j-light.jar放在报表环境目录\\WebReport\\WEB-INF\\lib文件夹下

4. UPCCODE()函数的使用

重启服务器,在报表中使用公式UPCCODE(num1, num2),num1为需要生成条形码的数值,num2为生成的图片的高度。

如输入公式:=UPCCODE(12345678912,100),预览便可以看到条形码了。

导出api

FineReport提供了强大的输入输出功能,所有的这些输入输出的类都在

com.fr.report.io包里面。Report的输入指从报表的模板文件(XML格式的)创建Report对象,输出指将Report保存为模板文件,FineReport还支持将Report保存为PDF,Excel,Word,SVG,HTML,CSV等文件格式。

读取模板文件 // 读取模板

File cptFile = new File(\);

TemplateImporter templateImporter = new TemplateImporter(); WorkBook workBook = (WorkBook)templateImporter.generate(cptFile);

Stuff.cpt是用报表设计器生成的模板文件。只需要用建立一个TemplateImporter对象, 然后调用它的generateReport()方法来产生一个Report对象,同时可以将产生的Report对象强制转换成WorkSheet或者GroupReport。

保存成模板文件

// CPT

// 清空公式计算结果

E:\\\\newtemplate\\\\stuff.cpt这个是导出后新文档生成的地址 ReportHelper.clearFormulaResult(workBook);

outputStream = new FileOutputStream(new File(\)); TemplateExporter templateExporter = new TemplateExporter(); templateExporter.export(outputStream,workBook.execute(parameterMap)) ;

通过调用TemplateExporter的exportReport(...)方法, 可以把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 */

public class ReportIO { /**

* @param args */

public static void main(String[] args) {

// 报表运行环境路径, WEB-INF目录所放的位置

String envPath = \ // 设置当前报表运行环境, 报表预览时需要一个运行环境

// 没有WEB-INF目录时, 路径设置为null. FRContext.setCurrentEnv(new LocalEnv(null));

FRContext.setCurrentEnv(new LocalEnv(envPath)); try {

// 读取模板

File cptFile = new File(\

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(\ TemplateExporter templateExporter = new TemplateExporter(); templateExporter.export(outputStream, workBook.execute(parameterMap)) ; //生成 PDF

ReportHelper.clearFormulaResult(workBook); outputStream = new FileOutputStream(new File(\

PDFExporter pdfExporter = new PDFExporter(); pdfExporter.export(outputStream, workBook.execute(parameterMap)) ; // 生成DOC

ReportHelper.clearFormulaResult(workBook); outputStream = new FileOutputStream(new File(\

WordExporter wordExporter = new WordExporter();

wordExporter.export(outputStream,workBook.execute(parameterMap));

// 生成XLS

ReportHelper.clearFormulaResult(workBook); outputStream = new FileOutputStream(new File(\

ExcelExporter excelExporter = new ExcelExporter();

excelExporter.export(outputStream,workBook.execute(parameterMap)); //生成 TXT

ReportHelper.clearFormulaResult(workBook); outputStream = new FileOutputStream(new File(\

TextExporter textExporter = new TextExporter(); textExporter.export(outputStream,workBook.execute(parameterMap)); } catch(Exception e) { e.printStackTrace();

} } }

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库FineReport报表软件API源代码之程序数据集、自定义函数和导出API(4)在线全文阅读。

FineReport报表软件API源代码之程序数据集、自定义函数和导出API(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/297931.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: