2012-04-24 18 views
0

サンプルコードを書こうとしましたが、できるだけ簡単に接続エラーが発生しています。問題jDDEを使用してJavaをExcelに接続

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); 
     } 
    } 
} 

私は、次のエラーメッセージになっている:私は、私はそれが両方のケースでは、ファイル名のみを渡してみました

conversation = ddeclient.connect(filename, sheetname); 

に完全なファイルパスを渡して最初に試み

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) 

をうまくいかなかった。

誰でも正しい方向に向けることができますか?

種類よろしく

+0

あなたはこれの最下部に到達しましたか?上記のコードでファイルが大きく開きますが、connectメソッドの最初のパラメータはサーバー上で実行されているサービス名です。サービスを稼働していたのですか、ローカルのExcelファイルで作業していましたか? – demongolem

+0

これは私のために働いた - 私は思うファイル名を変更しなければならなかった、覚えていない – Charbel

答えて

0

あなたはhttp://jdde.pretty-tools.com/から、例えば、同じ名前(JDDE)とのライブラリを別のライブラリを使用しようとすることができます。あなたはウェブサイトで例を見つけることができます。

関連する問題