2010-02-05 77 views
0

當我們嘗試關閉excel對象時,它無法關閉到羣集環境。在QA和UAT環境中工作正常。Excel進程在羣集環境中沒有結束

public bool KillExcelProcess() 
    { 
     try 
     { 
      object misValue = System.Reflection.Missing.Value; 
      wbObj.Save(); 
      wbObj.Close(true, misValue, misValue); 
      appC.Workbooks.Close(); 
      appC.Quit(); 
      System.Runtime.InteropServices.Marshal.ReleaseComObject(objSheet); 
      System.Runtime.InteropServices.Marshal.ReleaseComObject(wbObj); 
      System.Runtime.InteropServices.Marshal.ReleaseComObject(appC); 
      wbObj = null; 
      appC = null; 

     } 
     catch (Exception ex) 
     { 
      //throw ex; 
     } 
     finally 
     { 
      System.Threading.Thread.Sleep(5000); 
      GC.Collect(); 
     } 
     return true; 

調用函數

#endregion 
     try 
     { 
      log.Info("CloseExcelService (MeasureSavingsComputeBO) Starts ..."); 
      exConverter.KillExcelProcess(); 
      while (true) 
      { 
       try 
       { 
        File.Delete(strFilename); 
        break; 
       } 
       catch (Exception ex) 
       { 

       } 
      } 

回答

1

Microsoft建議對自動化Excel服務器端here

您可能需要考慮第三方組件,如,它是100%安全的託管代碼 - 沒有COM Interop問題,也沒有Excel的掛起實例。

您可以使用C#和VB源碼here查看實時ASP.NET樣本並下載免費試用版here

聲明:我自己的SpreadsheetGear LLC