0

我尝试编写示例代码 - 最简单的方法,我收到连接错误。

package my.excel.dde;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

import com.google.code.jdde.client.ClientConversation;
import com.google.code.jdde.client.DdeClient;

public class ExcelDdeExperiment {

    public static void main(String[] args) {
        final String filepath = "C:\\temp\\workbook1.xls";
        final String sheetname = "Sheet1";
        final DdeClient ddeclient = new DdeClient();
        ClientConversation conversation = null;
        String filename = null;

        try {
            Desktop desktop = Desktop.getDesktop();
            File file = new File(filepath);
            desktop.edit(file);
            filename = file.getName();

            conversation = ddeclient.connect(filename, sheetname);
            if (conversation != null) {
                System.out.println("successfully connected");
            }
        } catch (IOException e) {
            throw new RuntimeException("cannot open excel file: " + filepath, e);
        } catch (Throwable e) {
            throw new RuntimeException("cannot connect to excel file: " + filename, e);
        }
    }
}

我收到以下错误消息:

    Exception in thread "main" java.lang.RuntimeException: cannot connect to excel file: workbook1.xls
    at com.bfm.app.ldi.client.excel.dde.ExcelDdeExperiment.main(ExcelDdeExperiment.java:35)
Caused by: com.google.code.jdde.misc.DdeException: [DMLERR_NO_CONV_ESTABLISHED] A client's attempt to establish a conversation has failed.
    at com.google.code.jdde.ddeml.constants.DmlError.throwExceptionIfValidError(Unknown Source)
    at com.google.code.jdde.client.DdeClient.connect(Unknown Source)
    at com.bfm.app.ldi.client.excel.dde.ExcelDdeExperiment.main(ExcelDdeExperiment.java:28)

我尝试首先将完整的文件路径传递给

conversation = ddeclient.connect(filename, sheetname);

然后我尝试只传递文件名,在这两种情况下它都不起作用。

任何人都可以指出我正确的方向吗?

亲切的问候

4

1 回答 1

0

您可以尝试使用另一个库,例如来自http://jdde.pretty-tools.com/的同名库 (JDDE) 。您可以在网站上找到示例。

于 2013-08-20T15:46:17.373 回答