use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method addLastTableCol.
/**
* 在最后一列前增加一列
*
* @param tableIndex
* word文档中的第N张表(从1开始)
*/
public void addLastTableCol(int tableIndex) {
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
// 要填充的表格
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex)).toDispatch();
// 表格的所有行
Dispatch cols = Dispatch.get(table, "Columns").toDispatch();
Dispatch col = Dispatch.get(cols, "Last").toDispatch();
Dispatch.call(cols, "Add", col).toDispatch();
Dispatch.call(cols, "AutoFit");
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method copyTableFromAnotherDoc.
/**
* 在当前文档指定的位置拷贝来自另一个文档中的表格
*
* @param anotherDocPath
* 另一个文档的磁盘路径
* @param tableIndex
* 被拷贝的表格在另一格文档中的位置
* @param pos
* 当前文档指定的位置
*/
public void copyTableFromAnotherDoc(String anotherDocPath, int tableIndex, String pos) {
Dispatch doc2 = null;
try {
doc2 = Dispatch.call(documents, "Open", anotherDocPath).toDispatch();
// 所有表格
Dispatch tables = Dispatch.get(doc2, "Tables").toDispatch();
// 要填充的表格
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex)).toDispatch();
Dispatch range = Dispatch.get(table, "Range").toDispatch();
Dispatch.call(range, "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;
}
}
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method callWordMacro.
/**
* 调用word里的宏以调整表格的宽度,其中宏保存在document下
*
*/
public void callWordMacro() {
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
int count = Dispatch.get(tables, "Count").getInt();
Variant vMacroName = new Variant("Normal.NewMacros.tableFit");
@SuppressWarnings("unused") Variant vParam = new Variant("param1");
@SuppressWarnings("unused") Variant[] para = new Variant[] { vMacroName };
for (int i = 0; i < count; i++) {
Dispatch table = Dispatch.call(tables, "Item", new Variant(i + 1)).toDispatch();
Dispatch.call(table, "Select");
Dispatch.call(word, "Run", "tableFitContent");
}
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method addFirstTableRow.
/**
* 在第1行前增加一行
*
* @param tableIndex
* word文档中的第N张表(从1开始)
*/
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));
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method addTableRow.
/**
* 在指定行前面增加行
*
* @param tableIndex
* word文件中的第N张表(从1开始)
* @param rowIndex
* 指定行的序号(从1开始)
*/
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));
}
Aggregations