use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method copyTable.
/**
* 在当前文档指定的位置拷贝表格
*
* @param pos
* 当前文档指定的位置
* @param tableIndex
* 被拷贝的表格在word文档中所处的位置
*/
public void copyTable(String pos, int tableIndex) {
// 所有表格
Dispatch tables = Dispatch.get(doc, "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");
}
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method addFirstTableCol.
/**
* 在第1列前增加一列
*
* @param tableIndex
* word文档中的第N张表(从1开始)
*/
public void addFirstTableCol(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, "First").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 setHeaderContent.
/**
* 设置页眉文字
*
* @param cont
* @return
*
* Sub AddHeaderText() '设置页眉或页脚中的文字 '由 Headers、Footers 和
* HeaderFooter 属性返回 HeaderFooter 对象。下列示例更改当前页眉中的文字。 With
* ActiveDocument.ActiveWindow.View .SeekView =
* wdSeekCurrentPageHeader Selection.HeaderFooter.Range.Text =
* "Header text" .SeekView = wdSeekMainDocument End With End Sub
*/
public void setHeaderContent(String cont) {
Dispatch activeWindow = Dispatch.get(doc, "ActiveWindow").toDispatch();
Dispatch view = Dispatch.get(activeWindow, "View").toDispatch();
// Dispatch seekView = Dispatch.get(view, "SeekView").toDispatch();
// wdSeekCurrentPageHeader-9
Dispatch.put(view, "SeekView", new Variant(9));
Dispatch headerFooter = Dispatch.get(selection, "HeaderFooter").toDispatch();
Dispatch range = Dispatch.get(headerFooter, "Range").toDispatch();
Dispatch.put(range, "Text", new Variant(cont));
// String content = Dispatch.get(range, "Text").toString();
Dispatch font = Dispatch.get(range, "Font").toDispatch();
Dispatch.put(font, "Name", new Variant("宋体 (中文正文)"));
Dispatch.put(font, "Bold", new Variant(false));
// Dispatch.put(font, "Italic", new Variant(true));
// Dispatch.put(font, "Underline", new Variant(true));
Dispatch.put(font, "Size", 9);
// wdSeekMainDocument-0恢复视图;
Dispatch.put(view, "SeekView", new Variant(0));
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method getTxtFromCell.
/**
* 获得指定的单元格里数据
*
* @param tableIndex
* @param cellRowIdx
* @param cellColIdx
* @return
*/
public String getTxtFromCell(int tableIndex, int cellRowIdx, int cellColIdx) {
// 所有表格
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
// 要填充的表格
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex)).toDispatch();
Dispatch cell = Dispatch.call(table, "Cell", new Variant(cellRowIdx), new Variant(cellColIdx)).toDispatch();
Dispatch.call(cell, "Select");
String ret = "";
ret = Dispatch.get(selection, "Text").toString();
// 去掉最后的回车符;
ret = ret.substring(0, ret.length() - 1);
return ret;
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method mergeCell.
/**
* 合并当前表格指定的单元格 如果需要一次合并几个单元格只需要指出第一个单元格和最后一个单元格
*
* @param fstCellRowIndex
* 第一个单元格的行索引
* @param fstCellColIndex
* 第一个单元格的列索引
* @param secCellRowIndex
* 第二个单元格的行索引
* @param secCellColIndex
* 第二个单元格的列索引
*/
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);
}
Aggregations