用户登录
用户注册

分享至

javaword另存为html

  • 作者: 胡扯哥
  • 来源: 51数据库
  • 2020-04-21

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

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

如果你的JDK是1。4,那你需要下载jacob1。

9的jni库才能正常运行,早期版本在JDK1。4下有些问题。

package com;/** * Title:Word文档转html类 * Description: * Copyright:() 2002 * @author 舵手 * @version 1。 0 */import com。

jacob。com。

*;import com。jacob。

activeX。*; public class WordtoHtml { /** *文档转换函数 *@param docfile word文档的绝对路径加文件名(包含扩展名) *@param htmlfile 转换后的html文件绝对路径和文件名(不含扩展名) */ public static void change(String docfile, String htmlfile) { ActiveXComponent app = new ActiveXComponent("Word。

Application");// 启动word try { app。setProperty("Visible", new Variant(false)); //设置word不可见 Object docs = app。

getProperty("Documents")。 toDispatch(); Object doc = Dispatch。

invoke(docs,"Open",Dispatch。Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1])。

toDispatch(); // 打开word文件 Dispatch。invoke(doc, "SaveAs", Dispatch。

Method, new Object[] {htmlfile, new Variant(8) }, new int[1]); // 作为html格式保存到临时文件 Variant f = new Variant(false); Dispatch。 call(doc, "Close", f); } catch (Exception e) { e。

printStackTrace(); } finally { app。invoke("Quit", new Variant[]{}); } } public static void main(String[] strs){ WordtoHtml。

change("c:\\a\\运输管理调度系统总体方案。doc", "c:\\a\\t"); }}。

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

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

如果你的JDK是1。4,那你需要下载Jacob 1。

9的jni库才能正常运行,早期版本在JDK 1。4下有些问题。

以下是引用片段:package com;/*** 〈p〉Title:Word文档转html类〈/p〉* 〈p〉Description: 〈/p〉* 〈p〉Copyright:() 2002〈/p〉* @author 舵手* @version 1。 0*/import com。

jacob。com。

*;import com。jacob。

activeX。*;public class WordtoHtml {/***文档转换函数*@param docfile word文档的绝对路径加文件名(包含扩展名)*@param htmlfile 转换后的html文件绝对路径和文件名(不含扩展名)*/public static void change(String docfile, String htmlfile) {ActiveXComponent app = new ActiveXComponent("Word。

Application"); // 启动wordtry {app。setProperty("Visible", new Variant(false));//设置word不可见Object docs = app。

getProperty("Documents")。 toDispatch();Object doc = Dispatch。

invoke(docs,"Open",Dispatch。Method,new Object[]{ docfile, new Variant(false),new Variant(true) }, new int[1])。

toDispatch();// 打开word文件Dispatch。invoke(doc, "SaveAs", Dispatch。

Method, new Object[] {htmlfile,new Variant (8) }, new int[1]);// 作为html格式保存到临时文件Variant f = new Variant(false);Dispatch。 call(doc, "Close", f);} catch (Exception e) {e。

printStackTrace();} finally {app。invoke("Quit", new Variant[]{});}}public static void main(String[] strs){WordtoHtml。

change("c:\\a\\运输管理调度系统总体方案。doc", "c:\\a\\t");}}。

怎样用Java把word文档转换为html文档

在线学习的话应该是B/S模式吧,如果楼主是想将我word内容连同样式一起转换成html有两种方法

一种是手动将要上传的word文件另存为html文件,并将html文件传进服务器,由浏览器打开就行

另一种是使用控件将要上传的word文件内容转成html代码,现在较好的控件有FCKeditor,eWebEditor,前者免费,后者精简版免费,商业版支持直接上传word文件转成html代码,不过是收费的

源码的话真的没有,本人也是最近要做类似的项目,现学现卖的~

eWebEditor主页:

FCKeditor主页:

如何java程序将 word转换成html-CSDN论坛

Dispatch wordfile = Dispatch.invoke(

wordacc,

"Open",

Dispatch.Method,

new Object[] { ls_word, new Variant(false),

new Variant(true) }, new int[1]).toDispatch();

Dispatch.invoke(wordfile, "SaveAs", Dispatch.Method, new Object[] {

ls_html, new Variant(8) }, new int[1]);

Variant f = new Variant(false);

// 编写 生成的html

Dispatch.call((Dispatch) wordfile, "Close", (Object) f);

在执行Dispatch.invoke(wordfile, "SaveAs", Dispatch.Method, new Object[] {

ls_html, new Variant(8) }, new int[1]);

jacob.jar

jacob-1.14-x86.dll jacob-1.14-x64.dll 这些的位置有什么要求

抛出异常 路径绝对没有错

com.jacob.com.ComFailException: Invoke of: SaveAs

Source: Microsoft Word

Description: 这不是有效文件名。

请试用下列方法:

* 检查路径,确认键入无误。

* 从文件和文件夹列表中选择文件。

at com.jacob.com.Dispatch.invokev(Native Method)

at com.jacob.com.Dispatch.invokev(Dispatch.java:858)

at com.jacob.com.Dispatch.invoke(Dispatch.java:502)

java怎么由html生成word,保留html样式

@RequestMapping("download")

public void exportWord( HttpServletRequest request, HttpServletResponse response)

throws Exception {

User user = AppContext.getLoginUser();

Student student = studentSvc.findByUserId(user.getId());

try {

//word内容

String content="<html><body></body></html>";

byte b[] = content.getBytes("utf-8"); //这里是必须要设置编码的,不然导出中文就会乱码。

ByteArrayInputStream bais = new ByteArrayInputStream(b);//将字节数组包装到流中

/*

* 关键地方

* 生成word格式

*/

POIFSFileSystem poifs = new POIFSFileSystem();

DirectoryEntry directory = poifs.getRoot();

DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);

//输出文件

String fileName="实习考核鉴定表";

request.setCharacterEncoding("utf-8");

response.setContentType("application/msword");//导出word格式

response.addHeader("Content-Disposition", "attachment;filename=" +

new String( (fileName + ".doc").getBytes(),

"iso-8859-1"));

OutputStream ostream = response.getOutputStream();

poifs.writeFilesystem(ostream);

bais.close();

ostream.close();

}catch(Exception e){

AppUtils.logError("导出出错:%s", e.getMessage());

}

}

用java将文本文件转换成HTML文件要了解哪些知识

你会把数据从数据库里抓出来,拿到html上吗?现在无非是你用txt类似的文本文件,来存数据,但显示的时候还是要拿到html上的。

对于显示都是一样的,所以不存在“转成html”说法。读txt文件,你可以写成xml格式的,更好读一些,层次和逻辑更强,更能表达现实需求。

关键是java读取xml已经很成熟,dom4j,jdom这些第三方jar包都已深入到java技术的各个角落。网上教程也是一片片的,用法也大同小异,你搜搜看。

先学xml怎么写,再学java怎么读xml,然后读出数据来,显示的时候,以前你是怎么做html的,现在还怎么做就成了。如果不会,就找个最基础的讲html的。

哦,还需要看javascript,你多少会用到,有时间可以看看jQuery,能摆脱很多后台的繁琐操作,并简化页面代码。

请教java html导出word如何实现

java将html导出word不用忘记这对标签

//换页

mso-fareast-font-family:宋体;mso-font-kerning:1px;mso-ansi-language:EN-US;

mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA'>

//换行

查看的话 打开word 视图——页面 就能看出看出效果

[java] view plain copy print?

ArrayList records = form.getRecords();//获取数据库数据

if(null!=records&&0!=records.size()){

//html拼接出word内容

String content="";

for (int i = 0; i "+title+"

转载请注明出处51数据库 » javaword另存为html

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