jacob怎么配置呢?
推荐于2020-01-23 · 知道合伙人互联网行家
社会追梦小青年
知道合伙人互联网行家
向TA提问 私信TA
知道合伙人互联网行家
采纳数:470
获赞数:943
08年接触网络,熟悉Ddos、CC攻击、网站渗透、易语言、HTML、PHP、ASP、SEO、SEM等。从事互联网工作3年。
向TA提问 私信TA
关注
展开全部
配置说明:
1、解压文件:jacob1.1.5-M4.zip ,copy jacob.jar文件加入到classpath 和项目lib下;
2、 copy jacob-1.15-M4-x86.dll 放在java jdk bin目录下,系统目录/WINDOWS/system32目录下,如果服务器写入WORD报错可以检查一下服务器目录下/bin下是否有jacob- 1.15-M4-x86.dll文件;
jacob对应不同的JDK有不同的版本,此jacob版本(当然也有人说1.9版本和JDK1.6可以,但是没有具体试过,有兴趣的朋友不妨可以试以下)对应JDK1.6,作者在具体项目中实际用到,确定没问题。。
以下是一个测试操作word的实例:仅供参考
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComException;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class JacobTest {
// 声明一个word对象
private ActiveXComponent objWord;
// 声明四个word组件
private Dispatch custDocprops;
private Dispatch builtInDocProps;
private Dispatch document;
private Dispatch wordObject;
public JacobTest() {
}
/**
* 打开word文挡
*/
public void open(String filename) {
// 创建一个word对象
objWord = new ActiveXComponent("Word.Application");
// 为wordobject组件附值
wordObject = (Dispatch) (objWord.getObject()); // 改了这里
// 生成一个只读方式的word文挡组件
Dispatch.put(wordObject, "Visible", new Variant(false));
// 获取文挡属性
Dispatch documents = objWord.getProperty("Documents").toDispatch();
// 打开激活文挡
document = Dispatch.call(documents, "Open", filename).toDispatch();
}
public void selectCustomDocumentProperitiesMode() {
custDocprops = Dispatch.get(document, "CustomDocumentProperties").toDispatch();
}
public void selectBuiltinPropertiesMode() {
builtInDocProps = Dispatch.get(document, "BuiltInDocumentProperties").toDispatch();
}
/**
* 关闭文挡
*/
public void close() {
Dispatch.call(document, "Close");
}
public String getCustomProperty(String cusPropName) {
try {
cusPropName = Dispatch.call((Dispatch)custDocprops, "Item",cusPropName).toString();
} catch (ComException e) {
cusPropName = null;
}
return cusPropName;
}
public String getBuiltInProperty(String builtInPropName) {
try {
builtInPropName = Dispatch.call((Dispatch)builtInDocProps,"Item", builtInPropName).toString();
} catch (ComException e) {
builtInPropName = null;
}
return builtInPropName;
}
public static void main(String[] args) {
try {
JacobTest jacTest = new JacobTest();
jacTest.open("c:/s.doc");
jacTest.selectCustomDocumentProperitiesMode();
jacTest.selectBuiltinPropertiesMode();
String custValue = jacTest.getCustomProperty("Information Source");
String builtInValue = jacTest.getBuiltInProperty("Author");
jacTest.close();
System.out.println("Document Val One:" + custValue);
System.out.println("Document Author:" + builtInValue);
} catch (Exception e) {
System.out.println(e);
}
}
}
1、解压文件:jacob1.1.5-M4.zip ,copy jacob.jar文件加入到classpath 和项目lib下;
2、 copy jacob-1.15-M4-x86.dll 放在java jdk bin目录下,系统目录/WINDOWS/system32目录下,如果服务器写入WORD报错可以检查一下服务器目录下/bin下是否有jacob- 1.15-M4-x86.dll文件;
jacob对应不同的JDK有不同的版本,此jacob版本(当然也有人说1.9版本和JDK1.6可以,但是没有具体试过,有兴趣的朋友不妨可以试以下)对应JDK1.6,作者在具体项目中实际用到,确定没问题。。
以下是一个测试操作word的实例:仅供参考
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComException;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class JacobTest {
// 声明一个word对象
private ActiveXComponent objWord;
// 声明四个word组件
private Dispatch custDocprops;
private Dispatch builtInDocProps;
private Dispatch document;
private Dispatch wordObject;
public JacobTest() {
}
/**
* 打开word文挡
*/
public void open(String filename) {
// 创建一个word对象
objWord = new ActiveXComponent("Word.Application");
// 为wordobject组件附值
wordObject = (Dispatch) (objWord.getObject()); // 改了这里
// 生成一个只读方式的word文挡组件
Dispatch.put(wordObject, "Visible", new Variant(false));
// 获取文挡属性
Dispatch documents = objWord.getProperty("Documents").toDispatch();
// 打开激活文挡
document = Dispatch.call(documents, "Open", filename).toDispatch();
}
public void selectCustomDocumentProperitiesMode() {
custDocprops = Dispatch.get(document, "CustomDocumentProperties").toDispatch();
}
public void selectBuiltinPropertiesMode() {
builtInDocProps = Dispatch.get(document, "BuiltInDocumentProperties").toDispatch();
}
/**
* 关闭文挡
*/
public void close() {
Dispatch.call(document, "Close");
}
public String getCustomProperty(String cusPropName) {
try {
cusPropName = Dispatch.call((Dispatch)custDocprops, "Item",cusPropName).toString();
} catch (ComException e) {
cusPropName = null;
}
return cusPropName;
}
public String getBuiltInProperty(String builtInPropName) {
try {
builtInPropName = Dispatch.call((Dispatch)builtInDocProps,"Item", builtInPropName).toString();
} catch (ComException e) {
builtInPropName = null;
}
return builtInPropName;
}
public static void main(String[] args) {
try {
JacobTest jacTest = new JacobTest();
jacTest.open("c:/s.doc");
jacTest.selectCustomDocumentProperitiesMode();
jacTest.selectBuiltinPropertiesMode();
String custValue = jacTest.getCustomProperty("Information Source");
String builtInValue = jacTest.getBuiltInProperty("Author");
jacTest.close();
System.out.println("Document Val One:" + custValue);
System.out.println("Document Author:" + builtInValue);
} catch (Exception e) {
System.out.println(e);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询