我最近在研究jacob 用JAVA生成Excel表格和word。
结果就报错:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Java\jdk1.6.0\bin\jacob.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at com.jacob.com.LibraryLoader.loadJacobLibrary(LibraryLoader.java:57)
at com.jacob.com.JacobObject.<clinit>(JacobObject.java:150)
at com.sinosoft.module.lcc.WordBean.openWord(WordBean.java:22)
at com.sinosoft.module.lcc.WordTest.main(WordTest.java:14)
请问这是怎么回事啊??
在线等待,跪谢各位!!

解决方案 »

  1.   

    我用的jacob的版本是1.13
    JDK 是1.6
    Office 用的是 2003
      

  2.   

    那个dll放到system32下面了吗?貌似没找到dll文件
      

  3.   

    这个我 知道  我在system32  和 JDK\bin 里面都放了我现在把jacob1.13 换成了jacob1.9  现在我的程序在 eclipse 里面可以调试了
    但是 我把它放到我的项目中的时候又有新的错误了:javax.servlet.ServletException: Could not initialize class com.jacob.com.Variant
    org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:298)
    org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    com.wedz.struts.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:21)
    root cause java.lang.NoClassDefFoundError: Could not initialize class com.jacob.com.Variant
    util.ToExcel.closeDocument(ToExcel.java:61)
    com.wedz.actions.B201Action.toExcel(B201Action.java:925)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
    org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    com.wedz.struts.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:21)
    我用的是 Tomcat5.5
      

  4.   

    你的jacob.jar不在classpath里面,放到项目的web-info/lib下面去
      

  5.   

    WEB-INF/lib 里面我 放了 jacob.jar
      

  6.   

    肯定是类路径的问题,错误就是找不到类com.jacob.com.Variant
    而且,tomcat5.5和jdk6配套吗?记得应该配jdk5吧,不知道有没有关系
      

  7.   

    我的是jdk1.5用的是jacob1.11就可以的
    package com.meritit.gsedu.lore.support;import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.ComThread;
    import com.jacob.com.Dispatch;
    import com.jacob.com.Variant;
    import com.meritit.gsedu.other.MyDBConnect;public class WordUtils {
    private String filePath; private Connection con; /**
     * @author yuanyj since 2007-6-5 将数据库的word放到文件夹中
     * @param table
     * @param filebolb
     * @param id
     */
    public void db2Word(String table, String filebolb, String id) {
    String sql = "select files.id,files." + filebolb
    + " as content_v from " + table + " files where files.id='"
    + id + "'";
    try {
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    System.out.println("sql=" + sql);
    while (rs.next()) {
    oracle.sql.BLOB blob = (oracle.sql.BLOB) rs
    .getBlob("content_v");
    File wordFile = new File(filePath+"\\" + rs.getString("id") + ".doc");
    OutputStream os = new FileOutputStream(wordFile);
    InputStream is = blob.getBinaryStream();
    int i = 0;
    byte[] buffer = new byte[4 * 1024];
    while ((i = is.read(buffer)) != -1) {
    os.write(buffer, 0, i);
    }
    is.close();
    os.close();
    }
    rs.close();
    stmt.close(); } catch (Exception e) {
    System.err.println("SQL出错");
    System.err.println(sql);
    e.printStackTrace();
    }
    } /**
     * @author yuanyj since 2007-6-5 将文件夹的word文件转化成html文件
     * @param filename
     * @param savefilename
     * @param id
     */
    public void word2Html(String id) {
    ActiveXComponent app = new ActiveXComponent("Word.Application");
    try {
    app.setProperty("Visible", new Variant(false));
    // 设置word不可见
    Dispatch docs = app.getProperty("Documents").toDispatch();
    // 打开word文件
    Dispatch doc = Dispatch
    .invoke(
    docs,
    "Open",
    Dispatch.Method,
    new Object[] { this.filePath +"\\"+ id + ".doc",
    new Variant(false), new Variant(true) },
    new int[1]).toDispatch();
    // 作为html格式保存到临时文件.
    // 修改Variant(8),里面得参数即可将Word转化为各种类型。
    // Variant(8) 是html,Variant(9) 是mht,Variant(11)是xml
    Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {
    this.filePath+"\\" + id + ".html", new Variant(8) }, new int[1]);
    Dispatch.call(doc, "Close", new Variant(false));
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    Dispatch.call(app, "Quit", new Variant(0));
    ComThread.Release();
    app = null;
    } }
    public void delete(String id) {
    ActiveXComponent app = new ActiveXComponent("Word.Application");
    try {
    File file=new File(this.filePath +"\\"+ id + ".doc");
    if(file.exists()){
    file.delete();
    }
    file=new File(this.filePath +"\\"+ id + ".html");
    if(file.exists()){
    file.delete();
    }
    file=new File(this.filePath +"\\"+ id + ".files");
    if(file.isDirectory()){
    FileUtil.deleteDirs(file);
    }
    } catch (Exception e) {
    e.printStackTrace();
    } } public static void main(String[] args) {
    WordUtils u = new WordUtils();
    u.setFilePath("d:\\test");
    u.setCon(MyDBConnect.getConnect2());
    String table = "data_uploadfile";
    String filebolb = "content_v";
    String id = "A7760DCA5C4D4E64B992638CED96DA11";
    // u.db2Word(table, filebolb, id);
    // u.word2Html(id);
    u.delete(id);
    try {
    u.getCon().close();
    } catch (SQLException e) {
    System.err.println("关闭con出错");
    e.printStackTrace();
    }
    } public String getFilePath() {
    return filePath;
    } public void setFilePath(String filePath) {
    this.filePath = filePath;
    } public Connection getCon() {
    return con;
    } public void setCon(Connection con) {
    this.con = con;
    }}
      

  8.   

    我也卡在这里了:
    winxp
    jacob1.14
    tomcat6.014
    word2003
      

  9.   

    我在java main 方法中是可以调用,
    但发布到tomcat 6以后调用时就报那个错误
      

  10.   

    这是jacob在tomcate中的配置问题 
      

  11.   

    不知道楼主那个问题解决没有 用1.14的话 把 .dll文件放到 tomcat/bin 目录下就可以了