Click here to Skip to main content
15,946,074 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Excel File|*.xls|Excel File|*.xlsx";
            
            openFileDialog1.ShowDialog();
            
            string path = openFileDialog1.FileName;
            
            comboBox1.Items.Clear();

            Microsoft.Office.Interop.Excel.Application xlr = new            
            Microsoft.Office.Interop.Excel.Application();

            Workbook wb = xlr.Workbooks.Open(path, 0, false, 5, "", "", false, 
            XlPlatform.xlWindows, "", true, false, 0, true, false, false);

            foreach (Worksheet w in xlr.Worksheets)
            {
                comboBox1.Items.Add(w.Name);
            }

            xlr.Visible = true;

            wb.Close();
            xlr.Quit();

            System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlr);

        }



How can i safely dispose off/Release Excel COM objects in the above code??
Even after releasing in the above fashion i see that excel is running in the task manager under processes ...?
Posted
Updated 25-Dec-12 12:05pm
v2
Comments
austinbox 25-Dec-12 20:01pm    
After releasing the com object, you could try killing the process...

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900