use of com.jacob.com.Variant 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.Variant 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.Variant 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.Variant 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.Variant in project janrufmonitor by tbrandt77.
the class OutlookContactProxy method createContact.
public synchronized void createContact(ICaller c) throws OutlookContactProxyException {
ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
Dispatch mapiNS = null;
Dispatch contactsFolder = null;
Dispatch contactsSubFolder = null;
Dispatch items = null;
try {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("created Outlook.Application dispatch");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook version: " + Dispatch.get(outlook.getObject(), "Version"));
mapiNS = outlook.getProperty("Session").toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook namespace: " + mapiNS);
Variant contactsVariant = new Variant(10);
contactsFolder = Dispatch.call(mapiNS, "GetDefaultFolder", contactsVariant).toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook folder: " + contactsFolder);
contactsVariant.safeRelease();
String folder = this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY));
items = this.getItemsOfFolder(contactsFolder, folder, true);
if (items == null)
throw new OutlookContactProxyException("Error in Application Outlook. Folder <" + folder + "> could not be created");
Dispatch newContact = Dispatch.call(items, "Add").toDispatch();
boolean business = (c.getAttribute("outlook.business") != null && c.getAttribute("outlook.business").getValue().equalsIgnoreCase("true") ? true : false);
this.setContactData(newContact, c, business);
if (newContact != null)
newContact.safeRelease();
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Added new outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + ": " + c);
}
} catch (ComFailException ex) {
throw new OutlookContactProxyException("Error in Application Outlook.", ex);
} catch (Exception ex) {
throw new OutlookContactProxyException("Error in Application Outlook.", ex);
} finally {
// added 2006/02/05: clean outlook references
if (items != null)
items.safeRelease();
if (contactsFolder != null)
contactsFolder.safeRelease();
if (contactsSubFolder != null)
contactsSubFolder.safeRelease();
if (mapiNS != null)
mapiNS.safeRelease();
if (outlook != null)
outlook.safeRelease();
}
}
Aggregations