Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. public static void CloseExcel()
  2. {
  3. GC.Collect();
  4. GC.WaitForPendingFinalizers();
  5. if (_range != null)
  6. {
  7. Marshal.FinalReleaseComObject(_range);
  8. _range = null;
  9. }
  10. if (_workSheet != null)
  11. {
  12. Marshal.FinalReleaseComObject(_workSheet);
  13. _workSheet = null;
  14. }
  15. if (_workBook != null)
  16. {
  17. _workBook.Close(false, String.Empty, false);
  18. Marshal.FinalReleaseComObject(_workBook);
  19. _workBook = null;
  20. }
  21. if (_application != null)
  22. {
  23. try
  24. {
  25. _application.Quit();
  26. }
  27. Marshal.FinalReleaseComObject(_application);
  28. _application = null;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement