java 预览word文档 java在线预览word文档 - 电脑技术中心 - 【漳州电脑网】_漳州电脑维修_漳州笔记本电脑维修_监控安装_市区上门维修

全国统一24小时服务热线:400-0000-000400-0000-000  / 1399000000

当前位置:首页 > 电脑技术中心 > 正文

java 预览word文档 java在线预览word文档

发布日期:2020-09-25

摘要:Java程序把Word文档直接换成Html文件方法是什么呢? aco是Java和Windows下的Com桥,通过它我们可以在Java程序中调用COM组件。如果你的JDK是1 4,那你需要下载Jaco ...

java 预览word文档

Java程序把Word文档直接换成Html文件方法是什么呢?

aco是Java和Windows下的Com桥,通过它我们可以在Java程序中调用COM组件。

如果你的JDK是1.4,那你需要下载Jaco 1.9的jni库才能正常运行,早期版本在JDK 1.4下有些问题。

以下是引用片段:package com;*** 〈p〉Title:Wod文档转html类〈p〉* 〈p〉Desciption: 〈p〉* 〈p〉Copyight:() 2002〈p〉* @autho 舵手* @vesion 1.0*impot com.jaco.com.*;impot com.jaco.activeX.*;pulic class WodtoHtml {***文档转换函数*@paam docfile wod文档的绝对路径加文件名(包含扩展名)*@paam htmlfile 转换后的html文件绝对路径和文件名(不含扩展名)*pulic static void change(Sting docfile, Sting htmlfile) {ActiveXComponent app = new ActiveXComponent("Wod.Application"); 启动wodty {app.setPopety("Visile", new Vaiant(false));设置wod不可见Oject docs = app.getPopety("Documents").toDispatch();Oject doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Oject[]{ docfile, new Vaiant(false),new Vaiant(tue) }, new int[1]).toDispatch(); 打开wod文件Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Oject[] {htmlfile,new Vaiant (8) }, new int[1]); 作为html格式保存到临时文件Vaiant f = new Vaiant(false);Dispatch.call(doc, "Close", f);} catch (Exception e) {e.pintStackTace();} finally {app.invoke("Quit", new Vaiant[]{});}}pulic static void main(Sting[] sts){WodtoHtml.change("c:\\a\\运输管理调度系统总体方案.doc", "c:\\a\\t");}}

Java如何操作Word,Excel,PDF文档?

Java Excel API 文档 http://www.andykhan.com/jexcelapi/ 1、一个jacob操作Word的例子,其他操作excel,pdf的sample里都有 import java.io.File; import com.jacob.com.*; import com.jacob.activeX.*; public class WordTest { public static void main(String[] args) { WordBean word=new WordBean(); word.openWord(true); word.createNewDocument(); word.insertText("Hello word."); } } import com.jacob.activeX.*; import com.jacob.com.*; public class WordBean extends java.awt.Panel { private ActiveXComponent MsWordApp = null; private Dispatch document = null; public WordBean() { super(); } public void openWord(boolean makeVisible) { //Open Word if we"ve not done it already if (MsWordApp == null) { MsWordApp = new ActiveXComponent("Word.Application"); } //Set the visible property as required. Dispatch.put(MsWordApp, "Visible", new Variant(makeVisible)); } public void createNewDocument() { //Find the Documents collection object maintained by Word Dispatch documents = Dispatch.get(MsWordApp,"Documents").toDispatch(); //Call the Add method of the Documents collection to create //a new document to edit document = Dispatch.call(documents,"Add").toDispatch(); } public void insertText(String textToInsert) { // Get the current selection within Word at the moment. If // a new document has just been created then this will be at // the top of the new doc Dispatch selection = Dispatch.get(MsWordApp,"Selection").toDispatch(); //Put the specified text at the insertion point Dispatch.put(selection,"Text",textToInsert); } public void saveFileAs(String filename) { Dispatch.call(document,"SaveAs",filename); } public void printFile() { //Just print the current document to the default printer Dispatch.call(document,"PrintOut"); } public void closeDocument() { // Close the document without saving changes // 0 = wdDoNotSaveChanges // -1 = wdSaveChanges // -2 = wdPromptToSaveChanges Dispatch.call(document, "Close", new Variant(0)); document = null; } public void closeWord() { Dispatch.call(MsWordApp,"Quit"); MsWordApp = null; document = null; } }

java web实现在线预览word excel等文件,类似邮箱那种,非常感谢

幸运,我开发过又看到这个题。

开始我用的是openoffice,需要安装这个软件,再用java调用这样。

后面忘记出现了什么问题。

改用xcode,都是免费的,这个更方便,这是相当于另一个部署项目,在原先项目上直接通过url访问到xcode就可以浏览,其中url参数包括文件地址,及一些设置参数,有文档可以自己参考。

java实现word文档自动转成pdf文档我现在在做一个网站,客

没自动的..你可以把软件安装好了点文件-导入\导出 来转换成PDF文件 也可以用WPS, 这是我自己下载了在用的,很好用的版本: Office.2003.SP2.龙卷风大企业版 V2.2 2.2 658M ISO 此ISO整合SP2升级包,免激活,免序列号,支持在线更新 包含下列组件: Microsoft Office Word 2003 Microsoft Office Excel 2003 Microsoft Office PowerPoint 2003 Microsoft Office FrontPage 2003 Microsoft Office Access 2003 Microsoft Office Outlook 2003 Microsoft Office OneNote 2003 Microsoft Office Visio 2003 Microsoft Office InfoPath 2003 Microsoft Office Publisher 2003 Microsoft Office Project 2003 安装说明:先卸载你原来的版本,然后全新安装此版即可

JAVA读取WORD,EXCEL,PDF文件的方法是什么呢?

JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法 OFFICE文档使用POI控件,PDF可以使用PDFBOX0.7.3控件,完全支持中文,用XPDF也行,不过感觉PDFBOX比较好,而且作者也在更新。

水平有限,万望各位指正 WORD: impot og.apache.lucene.document.Document; impot og.apache.lucene.document.Field; impot og.apache.poi.hwpf.extacto.WodExtacto; impot java.io.File; impot java.io.InputSteam; impot java.io.FileInputSteam; impot com.seach.code.Index; pulic Document getDocument(Index index, Sting ul, Sting title, InputSteam is) thows DocCenteException { Sting odyText = null; ty { WodExtacto ex = new WodExtacto(is);is是WORD文件的InputSteam odyText = ex.getText(); if(!odyText.equals("")){ index.AddIndex(ul, title, odyText); } }catch (DocCenteException e) { thow new DocCenteException("无法从该Mociosoft Wod文档中提取内容", e); }catch(Exception e){ e.pintStackTace(); } } etun null; } Excel: impot og.apache.lucene.document.Document; impot og.apache.lucene.document.Field; impot og.apache.poi.hwpf.extacto.WodExtacto; impot og.apache.poi.hssf.usemodel.HSSFWokook; impot og.apache.poi.hssf.usemodel.HSSFSheet; impot og.apache.poi.hssf.usemodel.HSSFRow; impot og.apache.poi.hssf.usemodel.HSSFCell; impot java.io.File; impot java.io.InputSteam; impot java.io.FileInputSteam; impot com.seach.code.Index; pulic Document getDocument(Index index, Sting ul, Sting title, InputSteam is) thows DocCenteException { StingBuffe content = new StingBuffe(); ty{

JAVA中如何把WORD文档直接转换成html?

jaco是java和windows下的com桥,通过它我们可以在java程序中调用COM组件。

如果你的JDK是1.4,那你需要下载jaco1.9的jni库才能正常运行,早期版本在JDK1.4下有些问题。

package com;** * Title:Wod文档转html类 * Desciption: * Copyight:() 2002 * @autho 舵手 * @vesion 1.0 *impot com.jaco.com.*;impot com.jaco.activeX.*; pulic class WodtoHtml { ** *文档转换函数 *@paam docfile wod文档的绝对路径加文件名(包含扩展名) *@paam htmlfile 转换后的html文件绝对路径和文件名(不含扩展名) * pulic static void change(Sting docfile, Sting htmlfile) { ActiveXComponent app = new ActiveXComponent("Wod.Application"); 启动wod ty { app.setPopety("Visile", new Vaiant(false)); 设置wod不可见 Oject docs = app.getPopety("Documents").toDispatch(); Oject doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Oject[] { docfile, new Vaiant(false),new Vaiant(tue) }, new int[1]).toDispatch(); 打开wod文件 Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Oject[] {htmlfile, new Vaiant(8) }, new int[1]); 作为html格式保存到临时文件 Vaiant f = new Vaiant(false); Dispatch.call(doc, "Close", f); } catch (Exception e) { e.pintStackTace(); } finally { app.invoke("Quit", new Vaiant[]{}); } } pulic static void main(Sting[] sts){ WodtoHtml.change("c:\\a\\运输管理调度系统总体方案.doc", "c:\\a\\t"); }}

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

java读取word文档时,虽然网上介绍了很多插件poi、java2Word、jacob、itext等等,poi无法读取格式(新的API估计行好像还在处于研发阶段,不太稳定,做项目不太敢用);java2Word、jacob容易报错找不到注册,比较诡异,我曾经在不同的机器上试过,操作方法完全一致,有的机器不报错,有的报错,去他们论坛找高人解决也说不出原因,项目部署用它有点玄;itxt好像写很方便但是我查了好久资料没有见到过关于读的好办法。

经过一番选择还是折中点采用rtf最好,毕竟rtf是开源格式,不需要借助任何插件,只需基本IO操作外加编码转换即可。

rtf格式文件表面看来和doc没啥区别,都可以用word打开,各种格式都可以设定。

----- 实现的功能:读取rtf模板内容(格式和文本内容),替换变化部分,形成新的rtf文档。

----- 实现思路:模板中固定部分手动输入,变化的部分用$info$表示,只需替换$info$即可。

1、采用字节的形式读取rtf模板内容2、将可变的内容字符串转为rtf编码3、替换原文中的可变部分,形成新的rtf文档主要程序如下:public String bin2hex(String bin) {char[] digital = "0123456789ABCDEF".toCharArray();StringBuffer sb = new StringBuffer("");byte[] bs = bin.getBytes();int bit;for (int i = 0; i > 4;sb.append("\\"");sb.append(digital[bit]);bit = bs[i] & 0x0f;sb.append(digital[bit]);}return sb.toString(); }public String readByteRtf(InputStream ins, String path){ String sourcecontent =""; try{ ins = newFileInputStream(path); byte[] b= new byte[1024];if (ins == null) {System.out.println("源模板文件不存在");}int bytesRead = 0;while (true) {bytesRead = ins.read(b, 0, 1024); // return final read bytescountsif(bytesRead == -1) {// end of InputStreamSystem.out.println("读取模板文件结束");break;}sourcecontent += new String(b, 0, bytesRead); // convert to stringusing bytes} }catch(Exception e){ e.printStackTrace(); } return sourcecontent ;}以上为核心代码,剩余部分就是替换,从新组装java中的String.replace(oldstr,newstr);方法可以实现,在这就不贴了。

源代码部分详见附件。

运行源代码前提:c盘创建YQ目录,将附件中"模板.rtf"复制到YQ目录之下,运行OpreatorRTF.java文件即可,就会在YQ目录下生成文件名如:21时15分19秒_cheney_记录.rtf的文件。

package com;import java.io.File;import java.io.FileInputStream;import java.io.FileWriter;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import java.text.SimpleDateFormat;import java.util.Date;public class OperatorRTF {public String strToRtf(String content){char[] digital = "0123456789ABCDEF".toCharArray();StringBuffer sb = new StringBuffer("");byte[] bs = content.getBytes();int bit;for (int i = 0; i > 4;sb.append("\\"");sb.append(digital[bit]);bit = bs[i] & 0x0f;sb.append(digital[bit]);}return sb.toString();}public String replaceRTF(String content,String replacecontent,intflag){String rc = strToRtf(replacecontent);String target = "";if(flag==0){target = content.replace("$timetop$",rc);}if(flag==1){target = content.replace("$info$",rc);}if(flag==2){target = content.replace("$idea$",rc);}if(flag==3){target = content.replace("$advice$",rc);}if(flag==4){target = content.replace("$infosend$",rc);}return target;}public String getSavePath() {String path = "C:\\YQ";File fDirecotry = new File(path);if (!fDirecotry.exists()) {fDirecotry.mkdirs();}return path;}public String ToSBC(String input){char[] c =input.toCharArray();for (int i =0; i < c.length; i++){if (c[i] == 32){c[i] = (char) 12288;continue;}if (c[i] < 127){c[i] = (char) (c[i] + 65248);}}return newString(c);}public void rgModel(String username, String content) {// TODO Auto-generated method stubDate current=new Date();SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-ddHH:mm:ss");String targetname = sdf.format(current).substring(11,13) + "时";targetname += sdf.format(current).substring(14,16) + "分";targetname += sdf.format(current).substring(17,19) + "秒";targetname += "_" + username +"_记录.rtf";String strpath = getSavePath();String sourname = strpath+"\\"+"模板.rtf";String sourcecontent = "";InputStream ins = null;try{ins = new FileInputStream(sourname);byte[] b = new byte[1024];if (ins == null) {System.out.println("源模板文件不存在");}int bytesRead = 0;while (true) {bytesRead = ins.read(b, 0, 1024); // return final read bytescountsif(bytesRead == -1) {// end of InputStreamSystem.out.println("读取模板文件结束");break;}sourcecontent += new Strin...

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

为什么非要写道wod文档中? 你可以写进txt文件中,然后使用wod进行编辑 如果确实需要,请看下面的例子: impot java.io.File; impot java.io.FileInputSteam; impot java.io.FileOutputSteam; impot og.apache.poi.hwpf.extacto.WodExtacto; impot og.apache.poi.hwpf.model.io.HWPFOutputSteam; pulic class Wod { ** * 读取纯文本的wod文件 *pulic Sting eadWod(Sting doc) thows Exception { Sting context = null; WodExtacto extacto = null; 纯文本的遍历器 ty { FileInputSteam in = new FileInputSteam(new File(doc)); extacto = new WodExtacto(in); context = extacto.getText(); } catch (Exception e) { e.pintStackTace(); } etun context; } ** * 对wod文档做写操作 * *pulic oolean witeWod(Sting path, Sting content) thows Exception { oolean w = false; ty { yte [] = content.getBytes(); FileOutputSteam fs = new FileOutputSteam(path); HWPFOutputSteam hos = new HWPFOutputSteam(); hos.wite(, 0, .length); hos.witeTo(fs); hos.close(); w=tue; } catch (Exception e) { e.pintStackTace(); } etun w; } pulic static void main(Sting[] ags) { ReadWod w = new ReadWod(); ty{ Sting text = w.eadDoc("D:\\wokspace\\MyUntil\\t.doc"); w.witeDoc("D:\\wokspace\\MyUntil\\d.doc", text); }catch(Exception e){ e.pintStackTace(); } } } 所需的包请各位自己上apache的官网上poi工程目录下下吧 poi-3.5-final poi-conti-3.5-final poi-ooxml-3.5-final poi-scatchpad-3.5-final

上一篇:软件工程答辩ppt 软件工程毕业答辩ppt

下一篇:word分隔符使用说明 word分隔符