哪位高手能推荐一个关于Word ActiveX开发的源码

发布网友 发布时间:2022-04-25 22:23

我来回答

1个回答

热心网友 时间:2022-06-18 03:14

packagecom.cectsims.util;importjava.io.BufferedInputStream;importjava.io.File;importjava.io.IOException;importjava.io.InputStream;importcom.artofsolving.jodconverter.DocumentConverter;importcom.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;importcom.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;importcom.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;/***docdocx格式转换*/publicclassDocConverter{privatestaticfinalintenvironment=1;//环境1:windows2:linuxprivateStringfileString;//(只涉及pdf2swf路径问题)privateStringoutputPath="";//输入路径,如果不设置就输出在默认的位置privateStringfileName;privateFilepdfFile;privateFileswfFile;privateFiledocFile;publicDocConverter(StringfileString){ini(fileString);}/***重新设置file**@paramfileString*/publicvoidsetFile(StringfileString){ini(fileString);}/***初始化**@paramfileString*/privatevoidini(StringfileString){this.fileString=fileString;fileName=fileString.substring(0,fileString.lastIndexOf("."));docFile=newFile(fileString);pdfFile=newFile(fileName+".pdf");swfFile=newFile(fileName+".swf");}/***转为PDF**@paramfile*/privatevoiddoc2pdf()throwsException{if(docFile.exists()){if(!pdfFile.exists()){OpenOfficeConnectionconnection=newSocketOpenOfficeConnection(8100);try{connection.connect();DocumentConverterconverter=newOpenOfficeDocumentConverter(connection);converter.convert(docFile,pdfFile);//closetheconnectionconnection.disconnect();System.out.println("****pdf转换成功,PDF输出:"+pdfFile.getPath()+"****");}catch(java.net.ConnectExceptione){e.printStackTrace();System.out.println("****swf转换器异常,openoffice服务未启动!****");throwe;}catch(com.artofsolving.jodconverter.openoffice.connection.OpenOfficeExceptione){e.printStackTrace();System.out.println("****swf转换器异常,读取转换文件失败****");throwe;}catch(Exceptione){e.printStackTrace();throwe;}}else{System.out.println("****已经转换为pdf,不需要再进行转化****");}}else{System.out.println("****swf转换器异常,需要转换的文档不存在,无法转换****");}}/***转换成swf*/@SuppressWarnings("unused")privatevoidpdf2swf()throwsException{Runtimer=Runtime.getRuntime();if(!swfFile.exists()){if(pdfFile.exists()){if(environment==1){//windows环境处理try{//Processp=r.exec("D:/ProgramFiles/SWFTools/pdf2swf.exe"+pdfFile.getPath()+"-o"+swfFile.getPath()+"-T9");Processp=r.exec("C:/ProgramFiles(x86)/SWFTools/pdf2swf.exe"+pdfFile.getPath()+"-o"+swfFile.getPath()+"-T9");System.out.print(loadStream(p.getInputStream()));System.err.print(loadStream(p.getErrorStream()));System.out.print(loadStream(p.getInputStream()));System.err.println("****swf转换成功,文件输出:"+swfFile.getPath()+"****");if(pdfFile.exists()){pdfFile.delete();}}catch(IOExceptione){e.printStackTrace();throwe;}}elseif(environment==2){//linux环境处理try{Processp=r.exec("pdf2swf"+pdfFile.getPath()+"-o"+swfFile.getPath()+"-T9");System.out.print(loadStream(p.getInputStream()));System.err.print(loadStream(p.getErrorStream()));System.err.println("****swf转换成功,文件输出:"+swfFile.getPath()+"****");if(pdfFile.exists()){pdfFile.delete();}}catch(Exceptione){e.printStackTrace();throwe;}}}else{System.out.println("****pdf不存在,无法转换****");}}else{System.out.println("****swf已经存在不需要转换****");}}staticStringloadStream(InputStreamin)throwsIOException{intptr=0;in=newBufferedInputStream(in);StringBufferbuffer=newStringBuffer();while((ptr=in.read())!=-1){buffer.append((char)ptr);}returnbuffer.toString();}/***转换主方法*/@SuppressWarnings("unused")publicbooleanconver(){if(swfFile.exists()){System.out.println("****swf转换器开始工作,该文件已经转换为swf****");returntrue;}if(environment==1){System.out.println("****swf转换器开始工作,当前设置运行环境windows****");}else{System.out.println("****swf转换器开始工作,当前设置运行环境linux****");}try{doc2pdf();pdf2swf();}catch(Exceptione){e.printStackTrace();returnfalse;}if(swfFile.exists()){returntrue;}else{returnfalse;}}/***返回文件路径**@params*/publicStringgetswfPath(){if(swfFile.exists()){StringtempString=swfFile.getPath();tempString=tempString.replaceAll("\\\\","/");returntempString;}else{return"";}}/***设置输出路径*/publicvoidsetOutputPath(StringoutputPath){this.outputPath=outputPath;if(!outputPath.equals("")){StringrealName=fileName.substring(fileName.lastIndexOf("/"),fileName.lastIndexOf("."));if(outputPath.charAt(outputPath.length())=='/'){swfFile=newFile(outputPath+realName+".swf");}else{swfFile=newFile(outputPath+realName+".swf");}}}}转换为PDF,然后转换为SWF,网上很多这个过程的代码,你可以看看

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com