jsp文件怎么显示word文档

2025-04-08 20:05:31

1、利用jacob包将用户上传的word文件转换成htm格式,必须是“筛选过的网页”,不然显示不了图片;将转换好的htm格式文档路径存入数据库,读的时候就在数据库里读。

jsp文件怎么显示word文档

2、可能会抛出no jacob in java.library.path异常,解决办法如下:把jacob.dll在 C:/Program Files/Java/jdk1.5.0_08/bin、C:/Program Files/Java/jdk1.5.0_08/jre/bin、 C:/WINDOWS/system32 目录下各放一份

jsp文件怎么显示word文档

3、把jacob.jar放入 项目的lib包将word文档转换为htm格式的java代码如下import com.jacob.com.*;import com.jacob.activeX.*;import java.io.*;public class WordToHtml {

jsp文件怎么显示word文档

4、//将指定目录下面的指定doc文件转化为HTML并存储在savepaths目录下public static void change(Str足毂忍珩ing filepaths, String savepaths) {File f = new File(filepaths);String filename = f.getName();String filetype = filename.substring((filename.length() - 3), filename.length());// 取得文件类型if (filetype.equals("doc")) {// 判断是否为doc文件System.out.println("当前正在转换......");// 打印当前目录路径System.out.println(filepaths);ActiveXComponent app = new ActiveXComponent("Word.Application");// 启动wordString docpath = filepaths;String htmlpath = savepaths + filename.substring(0, (filename.length() - 4));String inFile = docpath;

jsp文件怎么显示word文档

5、// 要转换的word文件String tpFile = htmlpath;// HTML文件boolean flag = fa造婷用痃lse;try {app.setProperty("Visible", new Variant(false));// 设置word不可见Object docs = app.getProperty("Documents").toDispatch();Object doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { inFile, new Variant(false),new Variant(true) },new int[1]).toDispatch();// 打开word文件/** new Variant(10)筛选过的网页* new Variant(9) 单个文件网页* new Variant(8) 另存为网页* new Variant(7) 另存为txt格式* new Variant(6) 另存为rtf格式* new Variant(0) 另存为doc格式*/Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {tpFile, new Variant(10) }, new int[1]);// 作为html格式保存到临时文件Variant fl = new Variant(false);Dispatch.call(doc, "Close", fl);flag = true;} catch (Exception e) {e.printStackTrace();} finally {app.invoke("Quit", new Variant[] {});}System.out.println("转化完毕!");}public static void main(String[] args) {

jsp文件怎么显示word文档

6、//转换目录下的所有doc文件// String paths = new String("D://test//");String savepaths = new String("D://test//");// changeAll(paths, savepaths);////转换指定doc文件String filepaths = "D://test.doc";change(filepaths, savepaths);}}

jsp文件怎么显示word文档
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢