2

我正在尝试从 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);
}
4

2 回答 2

2

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

于 2009-12-29T12:38:19.600 回答
1

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

于 2009-02-04T11:39:04.083 回答