通过Jacob调用word中的宏命令

1. 下载jacob的包,将dll放到E:\Program Files\Java\jdk1.8.0_202\jre\bin目录下。

2. 引入依赖

<dependency>
    <groupId>io.github.osobolev</groupId>
    <artifactId>jacob</artifactId>
    <version>1.20</version>
</dependency>

3. 使用

//开始处理
ComThread.InitSTA();
ActiveXComponent word = new ActiveXComponent("Word.Application");
//设置应用操作是文档不在明面上显示,只在后台静默处理。
word.setProperty("Visible", new Variant(false));
Dispatch documents = word.getProperty("Documents").toDispatch();
//指定要打开的文档并且打开它
if(path.indexOf("/") == 0){
    path=path.substring(1);
}
Dispatch dis = Dispatch.call(documents, "Open", path).toDispatch();
//在这个文档上运行宏
Dispatch.call(word, "Run", new Variant("mathTypeToLatex"));
//如果要调用多个宏,要分开执行,不可以直接写在后面,那样会被当成参数,而不是一个宏。
word.invoke("Quit", new Variant[]{});
ComThread.Release();

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值