我最近在研究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)
请问这是怎么回事啊??
在线等待,跪谢各位!!
结果就报错:
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)
请问这是怎么回事啊??
在线等待,跪谢各位!!
JDK 是1.6
Office 用的是 2003
但是 我把它放到我的项目中的时候又有新的错误了: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
而且,tomcat5.5和jdk6配套吗?记得应该配jdk5吧,不知道有没有关系
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;
}}
winxp
jacob1.14
tomcat6.014
word2003
但发布到tomcat 6以后调用时就报那个错误