I have a bit of code that opens an xls workbook;
Excel.Workbooks workBooks;
workBooks = excelApp.Workbooks;
workbook = workBooks.Open(sourceFilePath + source
This question keeps popping up see:
How to properly clean up Excel interop objects in C#
You need to call System.Runtime.InteropServices.Marshal.ReleaseComObject() on every excel object you use, even invisible ones, e.g.:
var worksheet = excelApp.Worksheets.Open()
There are two objects here: 1. The obvious 'Worksheet' opened with Open() 2. The "invisible" collection 'Worksheets'.
Both of them need to be released (so you better keep a reference for Worksheets):
var wkCol = excelApp.Worksheets; var worksheet = wkCol.Open();