预览加载中,请您耐心等待几秒...
1/5
2/5
3/5
4/5
5/5

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

java将excel文件转换成pdf文件的方法java将excel文件转换成pdf文件的方法java将excel文件转换成pdf文件的原理是使用POI来读取excel的内容,将其写到pdf文件中。实现难度有点大,主要是因为excelsheet结构不固定,内容也不固定,可能存在图片等,导致读excel比较复杂,真正实现还是比较复杂的。下面是小编为大家带来的'java将excel文件转换成pdf文件的方法,欢迎阅读。java将excel文件转换成pdf文件的方法最近做一个项目,需要把excel文件转换成pdf文件,经过我查资料,无非使用两种方式:1POI+Itext2Jacob来调用excel另存功能。第一种方式,原理是使用POI来读取excel的内容,将其写到pdf文件中。实现难度有点大,主要是因为excelsheet结构不固定,内容也不固定,可能存在图片等,导致读excel比较复杂,真正实现还是比较复杂的。第二种方式,原来是使用jacob来调用excel文件的另存为pdf的功能。主要是熟悉jacob的API即可。不需要精巧的编程技巧。本文使用第二种方式,使用这种方式,需要在当前环境中安装office,pdf软件。建议安装office2010版本。如果安装的07版本,还需要安装一个excel插件(SaveAsPDFandXPS.exe)这个插件是微软官方的,链接如下:微软官方packagecom.bplead.module.sign.util;importcom.jacob.activeX.ActiveXComponent;importcom.jacob.com.Dispatch;importcom.jacob.com.Variant;publicclassTransferTool{publicstaticvoidels2pdf(Stringels,Stringpdf){System.out.println("Startingexcel...");longstart=System.currentTimeMillis();ActiveXComponentapp=newActiveXComponent("Excel.Application");try{app.setProperty("Visible",false);Dispatchworkbooks=app.getProperty("Workbooks").toDispatch();System.out.println("openingdocument:"+els);Dispatchworkbook=Dispatch.invoke(workbooks,"Open",Dispatch.Method,newObject[]{els,newVariant(false),newVariant(false)},newint[3]).toDispatch();Dispatch.invoke(workbook,"SaveAs",Dispatch.Method,newObject[]{pdf,newVariant(57),newVariant(false),newVariant(57),newVariant(57),newVariant(false),newVariant(true),newVariant(57),newVariant(true),newVariant(true),newVariant(true)},newint[1]);Variantf=newVariant(false);System.out.println("topdf"+pdf);Dispatch.call(workbook,"Close",f);longend=System.currentTimeMillis();System.out.println("completed..used:"+(end-start)/1000+"s");}catch(Exceptione){System.out.println("========Error:Operationfail:"+e.getMessage());}finally{if(app!=null){app.invoke("Quit",newVariant[]{});}}}publicstaticvoidmain(String[]args){els2pdf("f:ProjectTemplate.xlsx"