java 调用 office_[转载](转载)java调用com组件操作word使用总结(jacob)(2)

public void copyImageFromAnotherDoc(String anotherDocPath, int

shapeIndex,

String pos) {

Dispatch doc2 = null;

try {

doc2 = Dispatch.call(documents, "Open", anotherDocPath)

.toDispatch();

Dispatch shapes = Dispatch.get(doc2,

"InLineShapes").toDispatch();

Dispatch shape = Dispatch.call(shapes, "Item",

new Variant(shapeIndex)).toDispatch();

Dispatch imageRange = Dispatch.get(shape,

"Range").toDispatch();

Dispatch.call(imageRange, "Copy");

if (this.find(pos)) {

Dispatch textRange = Dispatch.get(selection, "Range")

.toDispatch();

Dispatch.call(textRange, "Paste");

}

} catch (Exception e) {

e.printStackTrace();

} finally {

if (doc2 != null) {

Dispatch.call(doc2, "Close", new Variant(saveOnExit));

doc2 = null;

}

}

}

public void createTable(String pos, int numCols, int numRows)

{

if (find(pos)) {

Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();

Dispatch range = Dispatch.get(selection,

"Range").toDispatch();

@SuppressWarnings("unused")

Dispatch newTable = Dispatch.call(tables, "Add", range,

new Variant(numRows), new Variant(numCols)).toDispatch();

Dispatch.call(selection, "MoveRight");

} else {

Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();

Dispatch range = Dispatch.get(selection,

"Range").toDispatch();

@SuppressWarnings("unused")

Dispatch newTable = Dispatch.call(tables, "Add", range,

new Variant(numRows), new Variant(numCols)).toDispatch();

Dispatch.call(selection, "MoveRight");

}

}

public void addTableRow(int tableIndex, int rowIndex) {

// 所有表格

Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();

// 要填充的表格

Dispatch table = Dispatch.call(tables, "Item", new

Variant(tableIndex))

.toDispatch();

// 表格的所有行

Dispatch rows = Dispatch.get(table, "Rows").toDispatch();

Dispatch row = Dispatch.call(rows, "Item", new

Variant(rowIndex))

.toDispatch();

Dispatch.call(rows, "Add", new Variant(row));

}

public void addFirstTableRow(int tableIndex) {

// 所有表格

Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();

// 要填充的表格

Dispatch table = Dispatch.call(tables, "Item", new

Variant(tableIndex))

.toDispatch();

// 表格的所有行

Dispatch rows = Dispatch.get(table, "Rows").toDispatch();

Dispatch row = Dispatch.get(rows, "First").toDispatch();

Dispatch.call(rows, "Add", new Variant(row));

}

public void addLastTableRow(int tableIndex) {

// 所有表格

Disp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值