サンプルコードを書いてみました-可能な限り簡単に、接続エラーが発生します。
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);
次に、ファイル名のみを渡してみましたが、どちらの場合も機能しませんでした。
誰でも私を正しい方向に向けることができますか?
敬具