package conversion;
import java.io.File;
import com.jacob.com.*;
import com.jacob.activeX.*;public class FileExtracter{
 public static void main(String[] args) {
  ActiveXComponent component = new ActiveXComponent("Word.Application");
  String inFile = "c:/test.doc";
 String tpFile = "c:/my.htm";
  String otFile = "c:/my.xml";
  boolean flag = false;
  try {
   component.setProperty("Visible", new Variant(false));
   Object wordacc = component.getProperty("document.").toDispatch();
   Object wordfile = Dispatch.invoke(wordacc,"Open", Dispatch.Method,
                                     new Object[]{inFile,new Variant(false), new Variant(true)},
                                     new int[1] ).toDispatch();
   Dispatch.invoke(wordfile,"SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]);
   Variant f = new Variant(false);
   Dispatch.call(wordfile, "Close", f);
   flag = true;
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   component.invoke("Quit", new Variant[] {});
  }
 }
}

解决方案 »

  1.   

    不知道你使用的哪一个包。还有,by the way看见代码不要乱抄。
      

  2.   

    因为别人在编译的时候使用了外面的包。找个包如果你没有的话(事实好像也的确如此),是运行不成功的。如果用jb编译的话,把需要的包加入即可。project-->project propeties.-->required libraries
      

  3.   

    你有没有 com.jacob 包?
      

  4.   

    我已经添加了JACOB这个包,而且我有另外一个程序也是用到这个包的运行成功,但是这个运行的时候会出现这样一个错误呢?还是不懂,我又重新添加了一次,但是还是没有成功.请帮忙