jacob在ActiveXComponent("Word.Application")初始化报错

java程序员小学生 2017-12-09 12:04:03
public WordBean() throws Exception {
// if (word == null) {
// word = new ActiveXComponent("Word.Application");
// word.setProperty("Visible", new Variant(visible)); // 不可见打开word
//// word.setProperty("AutomationSecurity", new Variant(3)); // 禁用宏
// }
// if (documents == null)
// documents = word.getProperty("Documents").toDispatch();
if (this.word == null||word.m_pDispatch==0) {
ComThread.InitSTA();
/* 初始化应用所要用到的对象实例 */
this.word = new ActiveXComponent("Word.Application"); //当程序运行到这一步没有初始化成功就会爆出异常了
/* 设置Word文档是否可见,true-可见false-不可见 */
this.word.setProperty("Visible", new Variant(false));
/* 禁用宏 */
this.word.setProperty("AutomationSecurity", new Variant(3));
}
if (this.documents == null||documents.m_pDispatch==0) {
this.documents = word.getProperty("Documents").toDispatch();
}
}


每当运行到上面标红的那个地方就报错误,dll文件都放对了位置了! 原先用wps测试可以,卸载wps 安装了office2007然后就一直是这个地方出问题!
请教大神怎么解决
...全文
1192 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fothin 2019-04-24
  • 打赏
  • 举报
回复
jacob的版本一定要与.dll的版本保持一致,否则代码:word = new ActiveXComponent("Word.Application"); 可能爆出null指针异常的错误
tianfang 2017-12-11
  • 打赏
  • 举报
回复
卸载office 取系统的ActiveXComponent , 就是office 2007中的word

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧