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)