Closing Excel File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ronin85
    New Member
    • Mar 2008
    • 2

    Closing Excel File

    Hi , I recently have much pain working with excel application especially closing excel . I try several method but with no success i try to urge garbage collector to dispose excel application object, I tried to kill excel process but i find it difficult to figure out which is the right process to kill .It is out of question to kill all process on the server so i have to find out which is the proper one bit I can't retrieve the id of the process after new excel application is created.I don't open excel in open window state otherwise it will be easy to retrieve the process id but ......

    So I'll be very grateful to any help , because it makes me crazy already.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    what method are you using to create the file, and what methods have you tried to destroy it?

    Jared

    Comment

    • Ronin85
      New Member
      • Mar 2008
      • 2

      #3
      Actually I don't create file I have prepared pattern to write in it.The new process is created when i started new excel application.I already come with solution to kill process but I am not quite convinced that i have the right solution.

      Dim i As Integer = 0

      For i = 1 To xlWrkBook.Works heets.Count
      xlWrkSheet = xlWrkBook.Works heets(i)
      System.Runtime. InteropServices .Marshal.Releas eComObject(xlWr kSheet)
      xlWrkSheet = Nothing
      Next
      For i = 1 To xlApp.Workbooks .Count
      xlWrkBook = xlApp.Workbooks (i)
      xlWrkBook.Close (False)
      System.Runtime. InteropServices .Marshal.Releas eComObject(xlWr kBook)
      xlWrkBook = Nothing
      Next

      xlApp.Quit()
      System.Threadin g.Thread.Sleep( 4000)
      System.Runtime. InteropServices .Marshal.Releas eComObject(xlAp p)
      xlApp = Nothing
      System.Threadin g.Thread.Curren tThread.Current Culture = oldCI

      GC.Collect()
      GC.WaitForPendi ngFinalizers()
      GC.Collect()
      GC.WaitForPendi ngFinalizers()

      this is the piece of code i tried to close excel , it have to work it is commonly use in my work but it doesn't work at me . I decided to write all process in hashtable and then start new excel application which generate EXCEL process
      and after that i find the new process and take id of the process and when it is needed i kill it. Good but i am not quite sure how this will work on server.

      Comment

      Working...