jacob 问题,很急,谢谢

aishangsuzimo 2009-09-04 11:04:53
package test;
import com.jacob.com.*;
import com.jacob.activeX.*;
import java.io.*;
public class WordtoHtml {
public static void changes(String paths,String savepaths){
File d=new File(paths);

// System.out.println(d.toString());

File lists[]=d.listFiles();
String pathss=new String("");
for(int i=0; i<lists.length; i++){
if(lists[i].isFile()){
String filename=lists[i].getName();
String filetype=new String("");
filetype=filename.substring(filename.length()-3,filename.length());
if(filetype.equals("doc")){
System.out.println("当前正在转换");
System.out.println(paths);
System.out.println(filename.substring(0,filename.length()-4));
ActiveXComponent app=new ActiveXComponent("Word.Application");//启动Word
String docpath=paths+filename;
String htmlpath=savepaths+filename.substring(0,filename.length()-4);
String infile=docpath;
String tpfile=htmlpath;
boolean flag=false;
try{
app.setProperty("Visible", new Variant(false));
// System.out.println(flag);
==============================================================================================================
Object docs=app.getProperty("Documents").toDispatch();
System.out.println("-----------------------");
Object doc=Dispatch.invoke(docs, "Open", Dispatch.Method,
new Object[]{infile,new Variant(false),new Variant(true)}, new int[1]).toDispatch();
Dispatch.invoke(doc,"SaveAs",Dispatch.Method,new Object[]{tpfile,new Variant(8)},new int[1]);
Variant f=new Variant(false);
Dispatch.call(doc, "Close", f);
flag=true;
}catch (Exception e){
e.printStackTrace();
}finally{
app.invoke("Quit", new Variant[]{});
}
System.out.println("转换完毕");
}
}
else{
System.out.println("Folder");
pathss=paths;
pathss=pathss+lists[i].getName()+"\\";
changes(paths,savepaths);
}
}
}

public static void main(String args[]) {
String paths=new String("E:\\参考简历\\");
String savepaths=new String("F:\\cs\\");
changes(paths,savepaths);
}

}


代码运行到===============线下报错,异常如下,高手请指教

com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Documents
Description: An unknown COM error has occured.
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.activeX.ActiveXComponent.getProperty(ActiveXComponent.java)
at test.WordtoHtml.changes(WordtoHtml.java:31)
at test.WordtoHtml.main(WordtoHtml.java:59)
Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Quit
Description: An unknown COM error has occured.
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.activeX.ActiveXComponent.invoke(ActiveXComponent.java)
at test.WordtoHtml.changes(WordtoHtml.java:42)
at test.WordtoHtml.main(WordtoHtml.java:59)
...全文
102 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
aishangsuzimo 2009-09-06
  • 打赏
  • 举报
回复
谢谢了,我尽快试一下
wzw_19850911 2009-09-04
  • 打赏
  • 举报
回复
我刚才试验了一下 用jacob1.9的会出现这样的错误 我换了一下用1.43版本的jacob 没问题 楼主换个低一点的版本试试

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧