public void DestoryExcel()
{
oBook.Close( false, null, null );
oExcel.Workbooks.Close();
oExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject( oRange );
System.Runtime.InteropServices.Marshal.ReleaseComObject( oWorkSheet );
System.Runtime.InteropServices.Marshal.ReleaseComObject( oSheet );
System.Runtime.InteropServices.Marshal.ReleaseComObject( oBook );
System.Runtime.InteropServices.Marshal.ReleaseComObject( oExcel );
oRange = null;
oWorkSheet = null;
oSheet = null;
oBook = null;
oMissing = null;
oExcel = null;
GC.Collect();
}

解决方案 »

  1.   

    workBook.SaveAs(this.FileName ,Excel.XlFileFormat.xlWorkbookNormal,Missing.Value ,Missing.Value ,
    Missing.Value ,Missing.Value ,Excel.XlSaveAsAccessMode.xlNoChange,Missing.Value ,Missing.Value ,Missing.Value ,
    Missing.Value );
    workBook.Saved = true;
    workBook.Close(false,null,null); 
    exApp.UserControl = false;
    exApp.Quit ();
    try
    {
    System.Runtime.InteropServices.Marshal.ReleaseComObject(workSheet);
    }
    catch(Exception e1)
    {
    System.Diagnostics.Debug.WriteLine(e1.Message);
    }
    try
    {
    System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
    }
    catch(Exception e2)
    {
    System.Diagnostics.Debug.WriteLine(e2.Message);
    }
    try
    {
    System.Runtime.InteropServices.Marshal.ReleaseComObject(exApp);
    }
    catch(Exception e3)
    {
    System.Diagnostics.Debug.WriteLine(e3.Message);
    }
    workSheet = null;
    workBook = null;
    exApp  = null;
    System.GC.Collect();