Search in sources :

Example 51 with Variant

use of com.jacob.com.Variant in project yyl_example by Relucent.

the class ExcelInvokeDemo method main.

public static void main(String[] s) {
    ComThread.InitSTA();
    // 获取ACTIVEX组件实例
    ActiveXComponent xl = new ActiveXComponent("Excel.Application");
    try {
        System.out.println("version=" + xl.getProperty("Version"));
        // 获取X1对象中version属性的值
        System.out.println("version=" + Dispatch.get(xl, "Version"));
        // 将true值赋给x1对象中的Visible属性
        Dispatch.put(xl, "Visible", new Variant(true));
        // 获得x1对象中的Workbooks属性,并将转为对象
        Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
        // 获得workbooks对象的add属性
        Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
        // 获得workbooks对象的ActiveSheet属性
        Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
        // 对sheet对象的Range属性执行其GET方法,再将Range属性的值设为A1
        Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get, new Object[] { "A1" }, new int[1]).toDispatch();
        // 同上
        Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get, new Object[] { "A2" }, new int[1]).toDispatch();
        // 将a1对象中的Value属性设为"123.456"
        Dispatch.put(a1, "Value", "123.456");
        Dispatch.put(a2, "Formula", "=A1*2");
        System.out.println("a1 from excel:" + Dispatch.get(a1, "Value"));
        System.out.println("a2 from excel:" + Dispatch.get(a2, "Value"));
        Variant f = new Variant(false);
        System.out.println(f);
    // Dispatch.call(workbook, "Close", f);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        xl.invoke("Quit", new Variant[] {});
        ComThread.Release();
    }
}
Also used : Variant(com.jacob.com.Variant) ActiveXComponent(com.jacob.activeX.ActiveXComponent) Dispatch(com.jacob.com.Dispatch)

Example 52 with Variant

use of com.jacob.com.Variant in project yyl_example by Relucent.

the class JacobWordEngine method addTableCol.

/**
   * 在指定列前面增加表格的列
   * 
   * @param tableIndex
   *        word文档中的第N张表(从1开始)
   * @param colIndex
   *        制定列的序号 (从1开始)
   */
public void addTableCol(int tableIndex, int colIndex) {
    // 所有表格
    Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
    // 要填充的表格
    Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex)).toDispatch();
    // 表格的所有行
    Dispatch cols = Dispatch.get(table, "Columns").toDispatch();
    System.out.println(Dispatch.get(cols, "Count"));
    Dispatch col = Dispatch.call(cols, "Item", new Variant(colIndex)).toDispatch();
    // Dispatch col = Dispatch.get(cols, "First").toDispatch();
    Dispatch.call(cols, "Add", col).toDispatch();
    Dispatch.call(cols, "AutoFit");
}
Also used : Variant(com.jacob.com.Variant) Dispatch(com.jacob.com.Dispatch)

Example 53 with Variant

use of com.jacob.com.Variant in project yyl_example by Relucent.

the class JacobWordEngine method setTableCellSelected.

/**
   * 设置单元格被选中
   * 
   * @param tableIndex
   * @param cellRowIdx
   * @param cellColIdx
   */
public void setTableCellSelected(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");
}
Also used : Variant(com.jacob.com.Variant) Dispatch(com.jacob.com.Dispatch)

Example 54 with Variant

use of com.jacob.com.Variant in project yyl_example by Relucent.

the class JacobWordEngine method closeDocumentWithoutSave.

public void closeDocumentWithoutSave() {
    if (doc != null) {
        Dispatch.call(doc, "Close", new Variant(false));
        doc = null;
    }
}
Also used : Variant(com.jacob.com.Variant)

Example 55 with Variant

use of com.jacob.com.Variant in project yyl_example by Relucent.

the class JacobWordEngine method setParagraphsProperties.

/**
   * 设置段落格式
   * 
   * @param alignment
   *        0-左对齐, 1-右对齐, 2-右对齐, 3-两端对齐, 4-分散对齐
   * @param lineSpaceingRule
   * @param lineUnitBefore
   * @param lineUnitAfter
   * @param characterUnitFirstLineIndent
   */
public void setParagraphsProperties(int alignment, int lineSpaceingRule, int lineUnitBefore, int lineUnitAfter, int characterUnitFirstLineIndent) {
    Dispatch paragraphs = Dispatch.get(selection, "Paragraphs").toDispatch();
    // 对齐方式
    Dispatch.put(paragraphs, "Alignment", new Variant(alignment));
    // 行距
    Dispatch.put(paragraphs, "LineSpacingRule", new Variant(lineSpaceingRule));
    // 段前
    Dispatch.put(paragraphs, "LineUnitBefore", new Variant(lineUnitBefore));
    // 段后
    Dispatch.put(paragraphs, "LineUnitAfter", new Variant(lineUnitAfter));
    // 首行缩进字符数
    Dispatch.put(paragraphs, "CharacterUnitFirstLineIndent", new Variant(characterUnitFirstLineIndent));
}
Also used : Variant(com.jacob.com.Variant) Dispatch(com.jacob.com.Dispatch)

Aggregations

Variant (com.jacob.com.Variant)100 Dispatch (com.jacob.com.Dispatch)45 ActiveXComponent (com.jacob.activeX.ActiveXComponent)18 ComFailException (com.jacob.com.ComFailException)17 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)6 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 SafeArray (com.jacob.com.SafeArray)1 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