【问题标题】:Is there a good reference for using OLE Automation (from Java)?是否有使用 OLE 自动化(来自 Java)的良好参考?
【发布时间】:2010-10-05 08:39:48
【问题描述】:

我正在尝试通过 Java/SWT 应用程序与 Excel 进行通信。我已经能够打开工作表、打开文件并保存它,但仅此而已。

谁能指出我的一些文档/示例?我特别需要知道哪些命令可用。我确实尝试记录宏来检查。这很有用,但并没有给我想要的一切。

这是迄今为止我一直在尝试的示例:

private static OleAutomation openFile(
        OleAutomation automation, String fileName) {
    Variant workbooks = automation.getProperty(0x0000023c);// get User
                                                            // Defined
                                                            // Workbooks
    Variant[] arguments = new Variant[1];

    arguments[0] = new Variant(fileName);
    System.out.println("workbooks::\t" + workbooks);

    IDispatch p1 = workbooks.getDispatch();
    int[] rgdispid = workbooks.getAutomation().getIDsOfNames(new String[] { "Open" });
    int dispIdMember = rgdispid[0];
    Variant workbook = workbooks.getAutomation().invoke(dispIdMember, arguments);
    System.out.println("Opened the Work Book");
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    int id = workbook.getAutomation().getIDsOfNames(new String[] { "ActiveSheet" })[0];
    System.out.println(id);
    Variant sheet = workbook.getAutomation().getProperty(id);
    OleAutomation sheetAutomation = sheet.getAutomation();

    return (sheetAutomation);
}

【问题讨论】:

    标签: java automation ole


    【解决方案1】:

    使用 VBA 帮助 MSOffice。您也可以在 Office 的 VB 编辑器中使用对象浏览器。

    【讨论】:

      【解决方案2】:

      不是文档,而是因为您询问了通过自动化提供的可用命令:您是否尝试过 Windows 2000 资源工具包附带的 OLE/COM 对象查看器?下载here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多