教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 高等教育 >

java - jacob - 操作word - 文档,进行写操作(7)

来源:网络收集 时间:2026-07-17
导读: } } /** */ /** * 在指定的单元格里填写数据 * * @param tableIndex * @param cellRowIdx * @param cellColIdx * @param txt */ public void putTxtToCell(Dispatch table, int cellRowIdx, int cellColIdx, String

} } /** */ /**

* 在指定的单元格里填写数据 *

* @param tableIndex * @param cellRowIdx * @param cellColIdx * @param txt */

public void putTxtToCell(Dispatch table, int cellRowIdx, int cellColIdx, String txt) {

Dispatch cell = Dispatch.call(table, \ new Variant(cellColIdx)).toDispatch(); Dispatch.call(cell, \

Dispatch selection = Dispatch.get(MsWordApp, \输入内容需要的对象

Dispatch.put(selection, \ }

/** */ /**

* 在指定的单元格里填写数据 *

* @param tableIndex * @param cellRowIdx * @param cellColIdx * @param txt */

public void putTxtToCell(int tableIndex, int cellRowIdx, int cellColIdx, String txt) { // 所有表格

Dispatch tables = Dispatch.get(document, \ // 要填充的表格

Dispatch table = Dispatch.call(tables, \ .toDispatch();

Dispatch cell = Dispatch.call(table, \ new Variant(cellColIdx)).toDispatch(); Dispatch.call(cell, \

Dispatch selection = Dispatch.get(MsWordApp, \输入内容需要的对象

Dispatch.put(selection, \ }

// 合并两个单元格

public void mergeCell(Dispatch cell1, Dispatch cell2) { Dispatch.call(cell1, \ }

public void mergeCell(Dispatch table, int row1, int col1, int row2, int col2) { Dispatch cell1 = Dispatch.call(table, \ new Variant(col1)).toDispatch();

Dispatch cell2 = Dispatch.call(table, \ new Variant(col2)).toDispatch(); mergeCell(cell1, cell2); }

public void mergeCellTest() {

Dispatch tables = Dispatch.get(document, \ int tableCount = Dispatch.get(tables, \ Variant.VariantInt).getInt(); // document中的表格数量

Dispatch table = Dispatch.call(tables, \ .toDispatch();// 文档中最后一个table

mergeCell(table, 1, 1, 1, 2);// 将table 中x=1,y=1 与x=1,y=2的两个单元格合并 }

// ========================================================

/** */ /**

* 把选定的内容或光标插入点向上移动 *

* @param pos * 移动的距离 */

public void moveUp(int pos) {

Dispatch selection = Dispatch.get(MsWordApp, \输入内容需要的对象

for (int i = 0; i < pos; i++) {

// MoveDown MoveLeft moveRight

// moveStart ( Dispatch.call(selection, \ // )

// moveEnd Dispatch.call(selection, \ Dispatch.call(selection, \ } } /** */ /**

* 从选定内容或插入点开始查找文本 *

* @param toFindText

* 要查找的文本

* @return boolean true-查找到并选中该文本,false-未查找到文本 */

public boolean find(String toFindText) { if (toFindText == null || toFindText.equals(\ return false;

Dispatch selection = Dispatch.get(MsWordApp, \输入内容需要的对象

// 从selection所在位置开始查询

Dispatch find = Dispatch.call(selection, \ // 设置要查找的内容

Dispatch.put(find, \ // 向前查找

Dispatch.put(find, \ // 设置格式

Dispatch.put(find, \ // 大小写匹配

Dispatch.put(find, \ // 全字匹配

Dispatch.put(find, \ // 查找并选中

return Dispatch.call(find, \ }

…… 此处隐藏:467字,全部文档内容请下载后查看。喜欢就下载吧 ……
java - jacob - 操作word - 文档,进行写操作(7).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/607438.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)