use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method putTxtToCell.
/**
* 在指定的单元格里填写数据
*
* @param tableIndex
* @param cellRowIdx
* @param cellColIdx
* @param txt
*/
public void putTxtToCell(int tableIndex, int cellRowIdx, int cellColIdx, String txt) {
// 所有表格
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");
Dispatch.put(selection, "Text", txt);
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method getParagraphs.
/**
* 读取文档中第paragraphsIndex段文字的内容;
*
* @param paragraphsIndex
* @return
*/
public String getParagraphs(int paragraphsIndex) {
String ret = "";
// 所有段落
Dispatch paragraphs = Dispatch.get(doc, "Paragraphs").toDispatch();
// 一共的段落数
int paragraphCount = Dispatch.get(paragraphs, "Count").getInt();
Dispatch paragraph = null;
Dispatch range = null;
if (paragraphCount > paragraphsIndex && 0 < paragraphsIndex) {
paragraph = Dispatch.call(paragraphs, "Item", new Variant(paragraphsIndex)).toDispatch();
range = Dispatch.get(paragraph, "Range").toDispatch();
ret = Dispatch.get(range, "Text").toString();
}
return ret;
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class JacobWordEngine method addCol.
/**
* 增加一列
*
* @param tableIndex
* word文档中的第N张表(从1开始)
*/
public void addCol(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.call(cols, "Add").toDispatch();
Dispatch.call(cols, "AutoFit");
}
use of com.jacob.com.Dispatch in project yyl_example by Relucent.
the class ActiveXComponentDemo method main.
public static void main(String[] s) {
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
Dispatch sControl = sC.getObject();
Dispatch.put(sControl, "Language", "VBScript");
// use COM component in same thread
Variant v = Dispatch.call(sControl, "Eval", "1+2*3");
System.out.println(v.toString());
}
use of com.jacob.com.Dispatch in project janrufmonitor by tbrandt77.
the class OutlookTransformer method setPictureAttribute.
private void setPictureAttribute(ICaller outlookCaller, Dispatch contact) {
try {
if (Dispatch.get(contact, "HasPicture").getBoolean()) {
String imagepath = MSO_IMAGE_CACHE_PATH + outlookCaller.getUUID() + ".jpg";
if (!new File(imagepath).exists()) {
Dispatch items = Dispatch.get(contact, "Attachments").toDispatch();
int count = Integer.valueOf(Dispatch.get(items, "Count").toString()).intValue();
if (count > 1)
this.m_logger.info("Found " + count + " attachments for outlook contact " + outlookCaller.toString());
for (int i = 1; i <= count; i++) {
Dispatch item = Dispatch.call(items, "Item", new Integer(i)).toDispatch();
int type = Integer.valueOf(Dispatch.get(item, "Type").toString()).intValue();
// type 1 olAttachmentType = olByValue
if (type == 1) {
try {
String outlookFilename = Dispatch.get(item, "FileName").toString();
if (outlookFilename != null && (outlookFilename.startsWith("ContactPicture") || outlookFilename.startsWith("ContactPhoto"))) {
// imagepath = imagepath.substring(0, imagepath.length()-4) + (i>1? Integer.toString(i) : "") + ".jpg";
Dispatch.call(item, "SaveAsFile", new String(imagepath));
}
} catch (ComFailException ex) {
this.m_logger.warning("Could not get FileName attribute: " + ex.getMessage() + ", " + ex.getSource());
}
}
}
}
IAttribute img = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(imagepath));
outlookCaller.setAttribute(img);
}
} catch (ComFailException ex) {
this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
}
}
Aggregations