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然后就一直是这个地方出问题!
请教大神怎么解决
...全文
1021 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fothin 2019-04-24
  • 打赏
  • 举报
回复
jacob的版本一定要与.dll的版本保持一致,否则代码:word = new ActiveXComponent("Word.Application"); 可能爆出null指针异常的错误
tianfang 2017-12-11
  • 打赏
  • 举报
回复
卸载office 取系统的ActiveXComponent , 就是office 2007中的word
一个简单示例 初始化当前Java线程STA ComThread InitSTA ; ActiveXComponent xl new ActiveXComponent "Excel Application" ; try{ 打开现有的Excel xl setProperty "Visible" new Variant false ; Dispatch workbooks xl getProperty "Workbooks" toDispatch ; Dispatch workbook Dispatch invoke workbooks "Open" Dispatch Method new Object[]{excelPath new Variant false 是否只读 new Variant false } 是否显示打开 new int[1] toDispatch ; 得到所有sheet Dispatch sheets Dispatch get workbook "sheets" toDispatch ; System out println "sheet数量:"+Dispatch get sheets "count" toString ; 根据索引得到sheet Dispatch sheet Dispatch invoke sheets "Item" Dispatch Get new Object[]{i} new int[1] toDispatch ; 绘图 Dispatch chartobjects Dispatch call sheet "ChartObjects" toDispatch ; Dispatch achart Dispatch invoke chartobjects "Add" Dispatch Method new Object[] { new Double 12 yHeight 横坐标 纵坐标 new Double 943 new Double 293 宽度 高度 } new int[1] toDispatch ; Dispatch chart Dispatch get achart "chart" toDispatch ; Dispatch range Dispatch invoke sheet "Range" Dispatch Get new Object[] {rangeX rangeY} 列名位置 数据位置 new int[2] toDispatch ; Dispatch series Dispatch call chart "seriescollection" toDispatch ; Dispatch call series "add" range new Variant true ; 生成图形 Dispatch put chart "PlotBy" "2" ; 纵向读取数据绘制chart 设置线条气泡颜色 黄色 Dispatch seriesChartFillFormat Dispatch get series "Fill" toDispatch ; Dispatch seriesForeColor Dispatch get seriesChartFillFormat "ForeColor" toDispatch ; Dispatch put s

67,513

社区成员

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

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