栏目导航
热点推荐
- 三十条有用的 Java 编程规则
- Java制作水印图片源码
- Java常见异常及可能的导致原因
- Java中的修饰词使用方法总结
- J2EE系统异常的处理准则
- Java中的异常、断言、日志解析(
- Java面试技巧:Java面试题集锦(
- 面向Java开发人员的Scala指南:
- Java程序员:一刻钟精通正则表达
- 网友经验分享:学好java开发的关
- 专家解答:创建表格与数据库进行
- Java远程访问Domino数据库
阅览排行
Java调用com组件操作word使用总结(jacob)
www.jz123.cn 2010-01-05 来源: 中国建站 责任编辑(袁袁) 我要投递新闻
/** * 把选定的内容或者插入点向右移动 * * @param pos * 移动的距离 */ public void moveRight(int pos) { if (selection == null) selection = Dispatch.get(word, "Selection").toDispatch(); for (int i = 0; i < pos; i++) Dispatch.call(selection, "MoveRight"); } /** * 把插入点移动到文件首位置 * */ public void moveStart() { if (selection == null) selection = Dispatch.get(word, "Selection").toDispatch(); Dispatch.call(selection, "HomeKey", new Variant(6)); } /** * 从选定内容或插入点开始查找文本 * * @param toFindText * 要查找的文本 * @return boolean true-查找到并选中该文本,false-未查找到文本 */ @SuppressWarnings("static-access") public boolean find(String toFindText) { if (toFindText == null || toFindText.equals("")) return false; // 从selection所在位置开始查询 Dispatch find = word.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"); // 查找并选中 return Dispatch.call(find, "Execute").getBoolean(); } /** * 把选定选定内容设定为替换文本 * * @param toFindText * 查找字符串 * @param newText * 要替换的内容 * @return */ public boolean replaceText(String toFindText, String newText) { if (!find(toFindText)) return false; Dispatch.put(selection, "Text", newText); return true; } /** * 全局替换文本 * * @param toFindText * 查找字符串 * @param newText * 要替换的内容 */ public void replaceAllText(String toFindText, String newText) { while (find(toFindText)) { Dispatch.put(selection, "Text", newText); Dispatch.call(selection, "MoveRight"); } } |
0
上一篇:Java通过jacob对excel,word进行打印等操作 下一篇:Java转义字符在正则表达式中的应用