6

私のC#プログラムでは、Excel2010相互運用機能アセンブリを使用しています。これで私はExcelファイルにデータを読み書きしています。そして、開発ボックス(Office 2010を含む)で正常に実行されます。クライアントマシンでは、Office2010とOfficePIAがありますが、以下の例外があり、WriteToExcel()メソッド呼び出しで発生します。

Unhandled Exception: System.MissingMethodException: Method not found: 'System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.GUID)'.

以下は私のコードスニペットです。

[STAThread]
static void Main(string[] args){

       // read user input, process and write data to Excel
       WriteToExcel();
 }

[STAThread]
static void WriteToExcel(){
     Application xlsApplication = new Application();
     Workbook xlsWorkbook = xlsApplication.Workbooks.Open(excelFilePath);
     // write data to excel
     // close up            
 }
4

2 に答える 2

5

.netバージョンを4.0に下げた後、問題は解決しました。以前の私のdevboxには4.5があり、アプリケーションはこのバージョンでコンパイルされています。私のクライアントマシンには4.0バージョンがあり、.netバージョンを下げると問題が解決しました。

于 2012-10-02T21:10:17.717 に答える
0

次のコードを使用してみてください。

[STAThread]
static void WriteToExcel()
{
    Application xlsApplication = new Application();
    var missing = System.Type.Missing;
    Workbook xlsWorkbook = xlsApplication.Workbooks.Open(excelFilePath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
    // write data to excel
    // close up            
 }
于 2012-09-29T18:26:41.467 に答える