use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method copyImageFromAnotherDoc.
/**
* 在当前文档指定的位置拷贝来自另一个文档中的图片
*
* @param anotherDocPath
* 另一个文档的磁盘路径
* @param shapeIndex
* 被拷贝的图片在另一格文档中的位置
* @param pos
* 当前文档指定的位置
*/
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;
}
}
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method pasteExcelSheet.
/**
* 在当前文档拷贝剪贴板数据
*
* @param pos
*/
public void pasteExcelSheet(String pos) {
moveStart();
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 setFont.
/**
* 设置当前选定内容的字体
*
* @param boldSize
* @param italicSize
* @param underLineSize
* 下划线
* @param colorSize
* 字体颜色
* @param size
* 字体大小
* @param name
* 字体名称
*/
public void setFont(boolean bold, boolean italic, boolean underLine, String size, String name) {
Dispatch font = Dispatch.get(selection, "Font").toDispatch();
Dispatch.put(font, "Name", new Variant(name));
Dispatch.put(font, "Bold", new Variant(bold));
Dispatch.put(font, "Italic", new Variant(italic));
Dispatch.put(font, "Underline", new Variant(underLine));
Dispatch.put(font, "Size", size);
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method setApplyTableFormat.
/**
* 设置当前文档中所有表格水平居中方式及其它一些格式,用在将word文件转化为html中,针对申报表
*/
public void setApplyTableFormat() {
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
// System.out.println(tabCount);
int tabCount = Integer.valueOf(Dispatch.get(tables, "Count").toString());
System.out.println("*******************************************************");
for (int i = 1; i <= tabCount; i++) {
Dispatch table = Dispatch.call(tables, "Item", new Variant(i)).toDispatch();
Dispatch rows = Dispatch.get(table, "Rows").toDispatch();
if (i == 1) {
// 1-居中,2-Right
Dispatch.put(rows, "Alignment", new Variant(2));
continue;
}
// 1-居中
Dispatch.put(rows, "Alignment", new Variant(1));
// 设置自动调整表格方式,1-根据窗口自动调整
Dispatch.call(table, "AutoFitBehavior", new Variant(1));
Dispatch.put(table, "PreferredWidthType", new Variant(1));
Dispatch.put(table, "PreferredWidth", new Variant(700));
System.out.println(Dispatch.get(rows, "HeightRule").toString());
// 0-自动wdRowHeightAuto,1-最小值wdRowHeightAtLeast,
Dispatch.put(rows, "HeightRule", new Variant(1));
// 2-固定wdRowHeightExactly
Dispatch.put(rows, "Height", new Variant(0.04 * 28.35));
// int oldAlign = Integer.valueOf(Dispatch.get(rows,
// "Alignment").toString());
// System.out.println("Algin:" + oldAlign);
}
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method find.
/**
* 从选定内容或插入点开始查找文本
*
* @param toFindText 要查找的文本
* @return boolean true查找到并选中该文本,false未查找到文本
*/
@SuppressWarnings("static-access")
public boolean find(String toFindText) {
if (toFindText == null || toFindText.equals(""))
return false;
// 从selection所在位置开始查询
Dispatch find = word.call(selection, "Find").toDispatch();
// 设置要查找的内容
Dispatch.put(find, "Text", toFindText);
// 向前查找
Dispatch.put(find, "Forward", "True");
// 设置格式
Dispatch.put(find, "Format", "True");
// 大小写匹配
Dispatch.put(find, "MatchCase", "True");
// 全字匹配
Dispatch.put(find, "MatchWholeWord", "True");
// 查找并选中
return Dispatch.call(find, "Execute").getBoolean();
}
Aggregations