title: How to open, read and close excel interop processes (C#)
body: <p>I have to do a program which reads an excel xlsx file and stores the data in to the database. This my actual simple code, I don't even take the values from the excel file, but I'm not able to kill the process. I've googled a lot and I've tried many things, but the excel process stays alive.</p>
  
  <pre><code>public void readFile(path)
          {
              try
              {
                  Microsoft.Office.Interop.Excel.Application xlApp = null;
                  Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
                  Microsoft.Office.Interop.Excel.Workbook xlWorkbook = null;
                  Microsoft.Office.Interop.Excel.Worksheet xlWorksheet = null;
                  Microsoft.Office.Interop.Excel.Range xlRange = null;
  
                  xlApp = new Microsoft.Office.Interop.Excel.Application();
                  workbooks = xlApp.Workbooks;
                  xlWorkbook = workbooks.Open(path);
                  xlWorksheet = xlWorkbook.Sheets[1];
                  xlRange = xlWorksheet.UsedRange;
  
                  //------Here is where I will read the data
  
                  xlWorkbook.Close();
                  workbooks.Close();
                  xlApp.Quit();
  
                  Marshal.FinalReleaseComObject(xlRange);
                  Marshal.FinalReleaseComObject(xlWorksheet);
                  Marshal.FinalReleaseComObject(xlWorkbook);
                  Marshal.FinalReleaseComObject(workbooks);
                  Marshal.FinalReleaseComObject(xlApp);
  
                  xlRange = null;
                  xlWorksheet = null;
                  xlWorkbook = null;
                  workbooks = null;
                  xlApp = null;
              }
              catch (Exception e)
              {
  
              }
          }
  </code></pre>
  
  <p>And the process stays alive. I hope you can help me.</p>