栏目导航
热点推荐
- 三十条有用的 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 newText * 要插入的新字符串 */ public void insertText(String newText) { Dispatch.put(selection, "Text", newText); } /** * * @param toFindText * 要查找的字符串 * @param imagePath * 图片路径 * @return */ public boolean replaceImage(String toFindText, String imagePath) { if (!find(toFindText)) return false; Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(), "AddPicture", imagePath); return true; } /** * 全局替换图片 * * @param toFindText * 查找字符串 * @param imagePath * 图片路径 */ public void replaceAllImage(String toFindText, String imagePath) { while (find(toFindText)) { Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(), "AddPicture", imagePath); Dispatch.call(selection, "MoveRight"); } } /** * 在当前插入点插入图片 * * @param imagePath * 图片路径 */ public void insertImage(String imagePath) { Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(), "AddPicture", imagePath); } /** * 合并单元格 * * @param tableIndex * @param fstCellRowIdx * @param fstCellColIdx * @param secCellRowIdx * @param secCellColIdx */ public void mergeCell(int tableIndex, int fstCellRowIdx, int fstCellColIdx, int secCellRowIdx, int secCellColIdx) { // 所有表格 Dispatch tables = Dispatch.get(doc, "Tables").toDispatch(); // 要填充的表格 Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex)) .toDispatch(); Dispatch fstCell = Dispatch.call(table, "Cell", new Variant(fstCellRowIdx), new Variant(fstCellColIdx)) .toDispatch(); Dispatch secCell = Dispatch.call(table, "Cell", new Variant(secCellRowIdx), new Variant(secCellColIdx)) .toDispatch(); Dispatch.call(fstCell, "Merge", secCell); } /** * 在指定的单元格里填写数据 * * @param tableIndex * @param cellRowIdx * @param cellColIdx * @param txt */ |
0
上一篇:Java通过jacob对excel,word进行打印等操作 下一篇:Java转义字符在正则表达式中的应用