2012-06-22 56 views

回答

0

您可以使用此代碼嘗試(可以使用互操作)

  var oExcel = new ApplicationClass(); 


      var oBook = oBooks.Open("c:\\test.xls", oMissing, oMissing, 
       oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, 
       oMissing, oMissing, oMissing, oMissing, oMissing, oMissing); 

      // Launch the macros (his name is Run). 
      RunMacro(oExcel, new Object[]{"arg1", "arg2"}); 

      // Quit Excel and clean up. 
      oBook.Close(false, oMissing, oMissing); 
      System.Runtime.InteropServices.Marshal.ReleaseComObject (oBook); 
      oExcel.Quit(); 



And function in order to launch macro 

private void RunMacro(object oApp, object[] oRunArgs) 
      { 

       oApp.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, oApp, oRunArgs); 
      } 
相關問題