Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Removing Excel object from Task Manager

C# Removing Excel object from Task Manager

Scheduled Pinned Locked Moved C#
csharpperformanceannouncement
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dsrao
    wrote on last edited by
    #1

    Hi All, I am unable to close Microsoft Excel object from Task Manager.what i am doing as follows ************ Sample Code********************* Excel._Application _excel = new Excel.ApplicationClass(); Excel.Workbook wsWorkbook = _excel.Workbooks.Open(@"C:\test.xls",0, false, 1, "", "", false, Excel.XlPlatform.xlWindows, "",true, false, 0, true, false, false); Excel._Worksheet sheet = (Excel._Worksheet)wsWorkbook.ActiveSheet; sheet.Activate(); ((Excel.Range)sheet.Cells [1,2]).EntireColumn.NumberFormat =0; ((Excel.Range)sheet.Cells [1,2]).EntireColumn.AutoFit(); ((Excel.Range)sheet.Cells [1,3]).EntireColumn.NumberFormat ="$#,##0.00"; ((Excel.Range)sheet.Cells [1,3]).EntireColumn.AutoFit(); wsWorkbook.Close(true,missing.Value,missing.Value ); // _excel.Visible = true; _excel.Quit(); MessageBox.Show("Done"); **************code end here*******************8 I am opening existing .xls file using C# and formatting some columns. It doesn't release object from Task manager memory. I used Excel.quit() and excel.close(); Please let me know why is object not realsed. Thanks & Regards Rao

    L M M 3 Replies Last reply
    0
    • D dsrao

      Hi All, I am unable to close Microsoft Excel object from Task Manager.what i am doing as follows ************ Sample Code********************* Excel._Application _excel = new Excel.ApplicationClass(); Excel.Workbook wsWorkbook = _excel.Workbooks.Open(@"C:\test.xls",0, false, 1, "", "", false, Excel.XlPlatform.xlWindows, "",true, false, 0, true, false, false); Excel._Worksheet sheet = (Excel._Worksheet)wsWorkbook.ActiveSheet; sheet.Activate(); ((Excel.Range)sheet.Cells [1,2]).EntireColumn.NumberFormat =0; ((Excel.Range)sheet.Cells [1,2]).EntireColumn.AutoFit(); ((Excel.Range)sheet.Cells [1,3]).EntireColumn.NumberFormat ="$#,##0.00"; ((Excel.Range)sheet.Cells [1,3]).EntireColumn.AutoFit(); wsWorkbook.Close(true,missing.Value,missing.Value ); // _excel.Visible = true; _excel.Quit(); MessageBox.Show("Done"); **************code end here*******************8 I am opening existing .xls file using C# and formatting some columns. It doesn't release object from Task manager memory. I used Excel.quit() and excel.close(); Please let me know why is object not realsed. Thanks & Regards Rao

      L Offline
      L Offline
      LeenaSo
      wrote on last edited by
      #2

      Add this in the end to release the objects :) wsWorkbook = null; _excel = null;

      1 Reply Last reply
      0
      • D dsrao

        Hi All, I am unable to close Microsoft Excel object from Task Manager.what i am doing as follows ************ Sample Code********************* Excel._Application _excel = new Excel.ApplicationClass(); Excel.Workbook wsWorkbook = _excel.Workbooks.Open(@"C:\test.xls",0, false, 1, "", "", false, Excel.XlPlatform.xlWindows, "",true, false, 0, true, false, false); Excel._Worksheet sheet = (Excel._Worksheet)wsWorkbook.ActiveSheet; sheet.Activate(); ((Excel.Range)sheet.Cells [1,2]).EntireColumn.NumberFormat =0; ((Excel.Range)sheet.Cells [1,2]).EntireColumn.AutoFit(); ((Excel.Range)sheet.Cells [1,3]).EntireColumn.NumberFormat ="$#,##0.00"; ((Excel.Range)sheet.Cells [1,3]).EntireColumn.AutoFit(); wsWorkbook.Close(true,missing.Value,missing.Value ); // _excel.Visible = true; _excel.Quit(); MessageBox.Show("Done"); **************code end here*******************8 I am opening existing .xls file using C# and formatting some columns. It doesn't release object from Task manager memory. I used Excel.quit() and excel.close(); Please let me know why is object not realsed. Thanks & Regards Rao

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        Office application does not quit after automation from Visual Studio .NET client[^]

        1 Reply Last reply
        0
        • D dsrao

          Hi All, I am unable to close Microsoft Excel object from Task Manager.what i am doing as follows ************ Sample Code********************* Excel._Application _excel = new Excel.ApplicationClass(); Excel.Workbook wsWorkbook = _excel.Workbooks.Open(@"C:\test.xls",0, false, 1, "", "", false, Excel.XlPlatform.xlWindows, "",true, false, 0, true, false, false); Excel._Worksheet sheet = (Excel._Worksheet)wsWorkbook.ActiveSheet; sheet.Activate(); ((Excel.Range)sheet.Cells [1,2]).EntireColumn.NumberFormat =0; ((Excel.Range)sheet.Cells [1,2]).EntireColumn.AutoFit(); ((Excel.Range)sheet.Cells [1,3]).EntireColumn.NumberFormat ="$#,##0.00"; ((Excel.Range)sheet.Cells [1,3]).EntireColumn.AutoFit(); wsWorkbook.Close(true,missing.Value,missing.Value ); // _excel.Visible = true; _excel.Quit(); MessageBox.Show("Done"); **************code end here*******************8 I am opening existing .xls file using C# and formatting some columns. It doesn't release object from Task manager memory. I used Excel.quit() and excel.close(); Please let me know why is object not realsed. Thanks & Regards Rao

          M Offline
          M Offline
          miah alom
          wrote on last edited by
          #4

          [DllImport("user32.dll", EntryPoint="GetWindowThreadProcessId")] public static extern uint GetWindowThreadProcessId(int Hwnd, ref int ProcessID); private int importExcelProcessID = 0; Do this in the beginning Excel._Application _excel = new Excel.ApplicationClass(); GetWindowThreadProcessId(_excel.Hwnd, ref this.importExcelProcessID); When the App ends do this if (this.importExcelProcessID != 0) { Process.GetProcessById(this.importExcelProcessID).Kill(); }

          D 2 Replies Last reply
          0
          • M miah alom

            [DllImport("user32.dll", EntryPoint="GetWindowThreadProcessId")] public static extern uint GetWindowThreadProcessId(int Hwnd, ref int ProcessID); private int importExcelProcessID = 0; Do this in the beginning Excel._Application _excel = new Excel.ApplicationClass(); GetWindowThreadProcessId(_excel.Hwnd, ref this.importExcelProcessID); When the App ends do this if (this.importExcelProcessID != 0) { Process.GetProcessById(this.importExcelProcessID).Kill(); }

            D Offline
            D Offline
            dsrao
            wrote on last edited by
            #5

            Thank you ... But doesn't work... Thanks & Regards Rao

            1 Reply Last reply
            0
            • M miah alom

              [DllImport("user32.dll", EntryPoint="GetWindowThreadProcessId")] public static extern uint GetWindowThreadProcessId(int Hwnd, ref int ProcessID); private int importExcelProcessID = 0; Do this in the beginning Excel._Application _excel = new Excel.ApplicationClass(); GetWindowThreadProcessId(_excel.Hwnd, ref this.importExcelProcessID); When the App ends do this if (this.importExcelProcessID != 0) { Process.GetProcessById(this.importExcelProcessID).Kill(); }

              D Offline
              D Offline
              dsrao
              wrote on last edited by
              #6

              Thank you ... Thanks & Regards Rao

              A 1 Reply Last reply
              0
              • D dsrao

                Thank you ... Thanks & Regards Rao

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #7

                Does it work for you? alam_pune

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups