Cannot close Excel.exe after Interop process

Simple rule: avoid using double-dot-calling expressions, such as this: var workbook = excel.Workbooks.Open(/*params*/) …because in this way you create RCW objects not only for workbook, but for Workbooks, and you should release it too (which is not possible if a reference to the object is not maintained). So, the right way will be: var workbooks … Read more

Closing Excel Application Process in C# after Data Access

Try this: excelBook.Close(0); excelApp.Quit(); When closing the work-book, you have three optional parameters: Workbook.close SaveChanges, filename, routeworkbook Workbook.Close(false) or if you are doing late binding, it sometimes is easier to use zero Workbook.Close(0) That is how I’ve done it when automating closing of workbooks. Also I went and looked up the documentation for it, and … Read more

Export the dataGridView to Excel with all the cells format

Update: Now available in GitHub: https://github.com/MeaningOfLights/DataGridToHTML I’m struggling to understand why this isn’t a duplicate. There are examples all over the net and here. To my surprise & after a lot of research there are no thorough examples of Exporting DataGridView to HTML or Excel with formatting anywhere on the internet – until now 🙂 … Read more

Fastest method to remove Empty rows and Columns From Excel Files using Interop

I found that looping through the excel worksheet can take some time if the worksheet is large. So my solution tried to avoid any looping in the worksheet. To avoid looping through the worksheet, I made a 2 dimensional object array from the cells returned from usedRange with: Excel.Range targetCells = worksheet.UsedRange; object[,] allValues = … Read more