急死了!!关于jacob配置的问题,各位大侠帮帮忙啊~~
我最近在研究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)
请问这是怎么回事啊??
在线等待,跪谢各位!!
[解决办法]
你的jacob.jar不在classpath里面,放到项目的web-info/lib下面去
[解决办法]
没遇到过,帮你顶
[解决办法]
肯定是类路径的问题,错误就是找不到类com.jacob.com.Variant
而且,tomcat5.5和jdk6配套吗?记得应该配jdk5吧,不知道有没有关系
[解决办法]
我的是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;
}
}