利用jacob给word 指定位置的文字添加超链接,思路先是通过搜索找到指定位置的文字,然后进行替换添加超链接,代码如下:

package com.jstrd.mobile.security;

import com.jacob.activeX.ActiveXComponent;import com.jacob.com.Dispatch;import com.jacob.com.Variant;

public class TestHyperlinks {   public static ActiveXComponent word;  public static Dispatch selection; public static Dispatch wordFile;  public static Dispatch documents;

//查找指定文字public static boolean find(String toFindText) {

    if (toFindText == null || toFindText.equals(""))        return false;    // 从selection所在位置开始查询    Dispatch find = Dispatch.call(selection, "Find").toDispatch();    // 设置要查找的内容    Dispatch.put(find, "Text", toFindText);    // 向前查找    Dispatch.put(find, "Forward", "True");    // 设置格式    Dispatch.put(find, "Format", "True");    // 大小写匹配    Dispatch.put(find, "MatchCase", "True");    // 全字匹配    Dispatch.put(find, "MatchWholeWord", "True");    // 查找并选中    boolean cc=  Dispatch.call(find, "Execute").getBoolean();

       return cc;}

public static void main(String[] args){

    String filePath = "E:\\test.doc";  word=new ActiveXComponent("Word.Application");

   word.setProperty("Visible", false);     Dispatch documents=word.getProperty("Documents").toDispatch();     Dispatch wordFile=Dispatch.invoke(documents, "Open", Dispatch.Method, new Object[]{filePath,new Variant(true),new Variant(false)}, new int[1]).toDispatch();       

  selection = word.getProperty("Selection").toDispatch();     while (find("指定文字")) {                  Object oRange = Dispatch.call(selection, "Range");         Dispatch Hyperlinks = Dispatch.get(wordFile, "Hyperlinks").toDispatch();       Dispatch.invoke(Hyperlinks, "Add", Dispatch.Method, new Object[] { oRange, new Variant("http://www.baidu.com"),new Variant("SubAddress"),  new Variant("{}"), new Variant("指定文字")}, new int[4]).toDispatch();                   Dispatch.call(selection, "MoveRight");

    }     System.out.println("扫描完毕!");      Dispatch.call(wordFile, "Close", new Variant(true));    Dispatch.call(word, "Quit");   }}

jacob 给word 指定位置添加超级链接相关推荐

  1. 【原】为DevExpress的ChartControl添加Y轴控制 和 GridControl中指定列添加超级链接

    一.控制ChartControl的Y轴范围 使用Devexpress中的CharControl控件,需要控制AxisY轴的显示范围,需要使用该控件的BoundDataChanged事件,具体代码如下: ...

  2. poi操作word替换模板向指定位置添加图表

    poi操作word替换模板向指定位置添加图表 首先是引入pom文件 <dependency><groupId>org.apache.poi</groupId>< ...

  3. 怎么将html链接加入到word中,如何在Word中插入目录超级链接?

    如何在Word中插入目录超级链接?在Word目录插入超级链接,可以帮助我们快速找到所需的内容,非常方便.如果你不知道如何插入的话,可以参考小编的操作步骤,希望可以帮助到大家. 方法/步骤: 1.首先打 ...

  4. java根据坐标在PDF指定位置添加文本

    目录 一.使用Aspose 1.前言: 2.创建一个模型 3.demo测试 二.使用Itext 1.前言 2.创建模型 3.测试demo 1)测试方法 2)实现代码 三.效果展示 一.使用Aspose ...

  5. python使用matplotlib可视化线图(line plot)、在可视化图像中的指定位置添加横线(add horizontal line in matplotlib plot)

    python使用matplotlib可视化线图(line plot).在可视化图像中的指定位置添加横线(add horizontal line in matplotlib plot) 目录

  6. pandas在dataframe指定位置添加新的数据列、使用insert函数

    pandas在dataframe指定位置添加新的数据列.使用insert函数 目录 pandas在dataframe指定位置添加新的数据列.使用insert函数 #仿真数据

  7. R语言ggplot2包和ggtext包在可视化图像中的指定位置添加文本框(横向文本框、竖向文本框)

    R语言ggplot2包和ggtext包在可视化图像中的指定位置添加文本框(横向文本框.竖向文本框) 目录

  8. js 对表格的动态操作(动态添加行,删除该行,在指定位置添加控件)

    ***************************************************************** js动态添加表的列,并在列中添加控件的方法<html> ...

  9. Python向DataFrame中指定位置添加一列或多列

    对于这个问题,相信很多人都会很困惑,本篇文章将会给大家介绍一种非常简单的方式向DataFrame中任意指定的位置添加一列. 在此之前或许有不少读者已经了解了最普通的添加一列的方式,如下: import ...

最新文章

  1. uboot引导kernel - 2- uboot/kernel需要放在DDR什么位置的问题
  2. lstm 文本纠错_中文文本纠错算法错别字纠正的二三事
  3. numpy.histogram
  4. Cell:重大突破!三位学术大咖,打造全新“DNA显微镜”
  5. HDU 1853 MCMF
  6. layui列表显示缩略图_layUI实现列表查询功能
  7. 通过组策略禁止用户安装任何软件
  8. linux bond 脚本,Linux--网卡聚合简单脚本(bond0)(示例代码)
  9. linux-basic(11)认识和学习bash
  10. 数据库设计三大范式应用实例剖析(讲得比较清楚)
  11. property和attribute的区别
  12. 在中國古代是沒有這種現象的
  13. 区块链 女巫攻击是什么 Sybil Attack 为什么POW可以抵御女巫攻击 一文看懂
  14. mysql 优化union_mysql优化 - MySQL中使用UNION进行两表合并,去重导致效率低下,请问如何优化?...
  15. ADAS功能中LCA、LKA、LCK...区别
  16. BLE 配对流程梳理
  17. input[type='radio'] 自定义样式___通过label标签重置input[radio]样式
  18. 为什么微信转账,对方收款要确认,而支付宝不用?
  19. 七种常见的数据分析法之:可行域分析
  20. 第904题 水果成篮

热门文章

  1. CAD打开多个文档只启动一个程序
  2. 包青天 - 乞丐王孙(4) 片段 - 堂审河南荥县县令马松友
  3. 购买你的青春和一切ZT
  4. 【期末考试】计算机组成原理突击复习
  5. 「Luogu4233」射命丸文的笔记-生成函数+多项式求逆
  6. centos8 修改root密码
  7. 国内外量化平台发展现状析
  8. lazada按关键字搜索商品
  9. htlm5实习报告_网页设计实习报告
  10. 决策树实例-泰坦尼克幸存者预测