用户登录
用户注册

分享至

java word2007转word20 java word2003转2007

  • 作者: 这是艺术懂不懂
  • 来源: 51数据库
  • 2020-04-14

java word2007转word20

如何在WORD2007中插入一个EXCEL文件效果是WORD20

new int[1]).toDispatch(),new Object[] { filePath };MS Publisher Color Printer"/** */PDFDistiller.PDFDistiller;/是否追加打印Variant Append = False.Documents的DispatchDispatch wrdDocs = wordCom.getProperty("Documents"//));/Adobe PDF"wordCom.setProperty("ActivePrinter&quot,返回wordDocwordDoc = Dispatch;/建立Adobe Distiller的com对象ActiveXComponent distiller = new ActiveXComponent("/作为输入的ps文档路径Variant inputPostScriptFilePath = new Variant(destinPSFilePath).Documents。

目前只使用了前5个参数, new Variant[] {Background, Append, Range;/*** * 将word文档打印为PS文件后,使用Distiller将PS文件转换为PDF文件 *** @param sourceFilePath* 源文件路径 ** @param destinPSFilePath* 首先生成的PS文件路径 ** @param destinPDFFilePath* 生成PDF文件路径*/.Variant;作为输出的pdf文档的路径Variant outputPDFFilePath = new Variant(destinPDFFilePath);//定义FileToPDF方法要使用adobe pdf设置文件的路径,在这里没有赋值表示并不使用pdf配置文件Variant PDFOption = new Variant("");//调用FileToPDF方法将ps文档转换为pdf文档Dispatch.callN(distiller, "FileToPDF", new Variant[] {inputPostScriptFilePath, outputPDFFilePath, PDFOption });System.out.println("由ps文档转换为pdf文档成功!");} catch (Exception ex) {ex.printStackTrace();} finally {closeWord();wordCom=null;//释放在程序线程中引用的其它com,比如Adobe PDFDistillerComThread.Release();}}public static void main(String[] argv) {D2P d2p = new D2P();d2p.docToPDF("d:/12.doc", "d:/1p.ps", "d:/1p.pdf");//这里是你建一个叫12.doc的word文档,生成的文档将在D盘下//1p.ps和1p.pdf(这是我们要的)}}.invoke(wrdDocs, &quot.invoke("Quit";设置当前使用的打印机,我的Adobe Distiller打印机名字为"/** */.1");try {///** */Open"public boolean openWord(String filePath) {///*** 关闭word文档*/public void closeWord() {///输出的postscript文件的路径Variant OutputFileName = new Variant(destinPSFilePath);public class D2P {private ActiveXComponent wordCom = null.jacob.Dispatch;import com, "PrintOut"需要用到插件jacob,自己去下载吧;//).println("打印所有文档int wdPrintAllDocument = 0;Variant Range = new Variant(wdPrintAllDocument);//*** 打开word文档** @param filePath* word文档* @return 返回word文档对象*//是否在后台运行Variant Background = False;/.out;/** *//** */import com.jacob.com.ComThread;import com。

import com.jacob.activeX.ActiveXComponent.Open方法打开指定的word文档, OutputFileName });System;Word.Application", new Variant("return true.toDispatch();//** */.com, new Variant[] {});}/** */Dispatch.callN((Dispatch) wordDoc.jacob,String destinPDFFilePath) {if (;由word文档打印为ps文档成功!");/public void docToPDF(String sourceFilePath, String destinPSFilePath;private Object wordDoc = null;/设置printout的参数,将word文档打印为postscript文档,如果要使用更多的话可以参考MSDN的office开发相关api/, Dispatch.Method,详细内容参考Distiller Api手册//返回wrdCom;private final Variant False = new Variant(false);private final Variant True = new Variant(true);建立ActiveX部件wordCom = new ActiveXComponent(&quot!openWord(sourceFilePath)) {closeWord();return;);关闭word文件wordCom;/调用Distiller对象的FileToPDF方法所用的参数;try {/} catch (Exception ex) {ex.printStackTrace();}return false;}/** *//调用wrdCom;/** */}/.com 展开

求教用java 生成word!!!

1-apache的POI,此方法对Excel的导出做的很好,目前对Word的导出方面的功能尚未完全。

2-纯JavaScript脚本实现。

主要通过客户端调用本机Office组件来实现。

3-在JSP页面引入头文件实现。

纯JavaScript脚本实现细节方面大体是创建一个word组件ActiveXObject('Word.Application'),用js通过表ID取得表内容然后保存到word,要注意的是js实现有很多不好的地方,例如Internet选项需要把ActiveX空间全部启用,安全级别设置为中。

这样的话岂不是每台机器都要配置一下。

其次每次生成word文档以后弹出对话框(无法保存此文件,因为它已在别处打开(C:\...\STARTUP\Powerword.dot)),出现此问题就需要把C:\Documents and Settings\当前用户名\Application Data\Microsoft\Word\STARTUP下的Powerword.dot文件删除,每次遇到此问题就需要删除文件来解决,十分不方便。

JSP页面引入来实现Word保存就方便多了,但是也有不足的地方,首先如果需要引入如果需要下载的话就引入其实如果大家用框架做就方便多了,比如Struts2。

在Action里直接写如下代码:if(out!=null){String fileName="";fileName+="评价报告.doc";try {HttpServletResponse response = ServletActionContext.getResponse();response.setHeader("Content-disposition","attachment; filename="+new String(fileName.getBytes("GB2312"), "8859_1"));} catch (UnsupportedEncodingException e) {e.printStackTrace();}out是jsp页面表单元素,一个button,用于提交表单到相应Action进行Word下载。

Action设置jsp页面头文件。

这样每次点击button就可以把相应jsp页面的内容保存到Word中并且支持下载,Word中内容并且是可编辑状态。

不足的地方在于由于表内容是动态生成,有的需要先查看在下载Word,就需要另外建立一个新JSP页面进行Word下载,当然首先要在struts.xml里配置好页面转向。

新建立的页面传值同查看页面要保持一样。

如何使用java代码实现pdf文档转成Word文档?

使用java中的io进行读取BufferedReader bufferedReader = null;File file = new File("文档地址+文档名.docx");if(!file.exists()){System.out.println("文件不存在");} else {bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "读取的字符格式(UTF-8或GBK)"));String lineText = null;while((lineText = bufferedReader.readLine()) != null){if (linText != null && !lineText.eq("")){System.out.println("一次读取一行,一行内容为:" + lineText);

如何用纯java代码实现word转pdf

然后转成html文件用Jsoup格式化html文件,用来把word转化为pdf)Office版本是2007,可以把doc转换成pdf,html:使用jodconverter来调用openOffice的服务来转换.exe(word的一个插件,而且速度是最慢的需要安装msofficeWord以及SaveAsPDFandXPS,具体启动方法请自行google方法4:效果最好的一种方法,但是需要window环境,所以这种方法跟方法1一样都是跨平台的。

安装完后要启动openOffice的服务,最后用itext将html文件转成pdf。

方法2:使用jdoctopdf来实现。

方法3,openOffice有个各个平台的版本,xml等格式,调用很方便需要注意中文字体的写入问题,这是一个封装好的包:用apache pio 读取doc文件:方法一几种方案...

Java 生成大型Word文档,有没有好的解决方案

word软件 左上角点那个圆形图标然后点另存为选择“97-2003兼容格式”这样保存出来的文件就可以在2003版的WORD上打开了或者你给装有2003版的电脑上装一个2007兼容插件(网上可以下到),这样2003版的WORD也能打开2007版本的那种DOCX的文件

转载请注明出处51数据库 » java word2007转word20

软件
前端设计
程序设计
Java相关