Search in sources :

Example 36 with Dispatch

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);
}
Also used : Variant(com.jacob.com.Variant) Dispatch(com.jacob.com.Dispatch)

Example 37 with Dispatch

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;
}
Also used : Variant(com.jacob.com.Variant) Dispatch(com.jacob.com.Dispatch)

Example 38 with Dispatch

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");
}
Also used : Variant(com.jacob.com.Variant) Dispatch(com.jacob.com.Dispatch)

Example 39 with Dispatch

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());
}
Also used : Variant(com.jacob.com.Variant) ActiveXComponent(com.jacob.activeX.ActiveXComponent) Dispatch(com.jacob.com.Dispatch)

Example 40 with Dispatch

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());
    }
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) Dispatch(com.jacob.com.Dispatch) File(java.io.File) ComFailException(com.jacob.com.ComFailException)

Aggregations

Dispatch (com.jacob.com.Dispatch)50 Variant (com.jacob.com.Variant)45 ComFailException (com.jacob.com.ComFailException)19 ActiveXComponent (com.jacob.activeX.ActiveXComponent)18 Message (de.janrufmonitor.exception.Message)13 ICallerList (de.janrufmonitor.framework.ICallerList)13 ZipArchiveException (de.janrufmonitor.repository.zip.ZipArchiveException)13 SQLException (java.sql.SQLException)13 ArrayList (java.util.ArrayList)13 List (java.util.List)13 IAttribute (de.janrufmonitor.framework.IAttribute)8 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 ICaller (de.janrufmonitor.framework.ICaller)1 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 UUID (de.janrufmonitor.util.uuid.UUID)1 Properties (java.util.Properties)1