Excel Interop, lingering instances of Excel










0














Simple code, and I thought it should kill Excel. But the task manager says this leaves an instance of Excel running. What am I missing? Thank you.



using Microsoft.Office.Interop.Excel;
//Stuff...
// Launch dialog picker that return path to Excel file, in string
// called excelTemplate
Microsoft.Office.Interop.Excel.Application xlTemp = new Microsoft.Office.Interop.Excel.Application();
Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
xlTemp.DisplayAlerts = false;

// Poke through individual sheets, get some info from them

workbook.Close();
xlTemp.Quit();









share|improve this question

















  • 1




    Possible duplicate of Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?
    – mjwills
    Nov 13 '18 at 1:24










  • See also my comment at stackoverflow.com/questions/50927453/… .
    – mjwills
    Nov 13 '18 at 1:24










  • It occurred to me that the search through the worksheets probably leaves it on a different worksheet than when it opened, but DisplayAlerts = false would suppress the "do you want to save" box.... So I tried adding object misValue = System.Reflection.Missing.Value; and specifying workbook.Close(false, misValue, misValue); That did not help.
    – Aram Schiffman
    Nov 13 '18 at 1:35










  • Excel Interop was designed to make developers hate their lives. I recommend checking out EPPlus. You don't need an open instance of Excel running to open a spreadsheet and read it. You don't even need Excel installed. You just open it like a document and read what you want. github.com/JanKallman/EPPlus
    – Scott Hannen
    Nov 13 '18 at 2:25















0














Simple code, and I thought it should kill Excel. But the task manager says this leaves an instance of Excel running. What am I missing? Thank you.



using Microsoft.Office.Interop.Excel;
//Stuff...
// Launch dialog picker that return path to Excel file, in string
// called excelTemplate
Microsoft.Office.Interop.Excel.Application xlTemp = new Microsoft.Office.Interop.Excel.Application();
Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
xlTemp.DisplayAlerts = false;

// Poke through individual sheets, get some info from them

workbook.Close();
xlTemp.Quit();









share|improve this question

















  • 1




    Possible duplicate of Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?
    – mjwills
    Nov 13 '18 at 1:24










  • See also my comment at stackoverflow.com/questions/50927453/… .
    – mjwills
    Nov 13 '18 at 1:24










  • It occurred to me that the search through the worksheets probably leaves it on a different worksheet than when it opened, but DisplayAlerts = false would suppress the "do you want to save" box.... So I tried adding object misValue = System.Reflection.Missing.Value; and specifying workbook.Close(false, misValue, misValue); That did not help.
    – Aram Schiffman
    Nov 13 '18 at 1:35










  • Excel Interop was designed to make developers hate their lives. I recommend checking out EPPlus. You don't need an open instance of Excel running to open a spreadsheet and read it. You don't even need Excel installed. You just open it like a document and read what you want. github.com/JanKallman/EPPlus
    – Scott Hannen
    Nov 13 '18 at 2:25













0












0








0







Simple code, and I thought it should kill Excel. But the task manager says this leaves an instance of Excel running. What am I missing? Thank you.



using Microsoft.Office.Interop.Excel;
//Stuff...
// Launch dialog picker that return path to Excel file, in string
// called excelTemplate
Microsoft.Office.Interop.Excel.Application xlTemp = new Microsoft.Office.Interop.Excel.Application();
Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
xlTemp.DisplayAlerts = false;

// Poke through individual sheets, get some info from them

workbook.Close();
xlTemp.Quit();









share|improve this question













Simple code, and I thought it should kill Excel. But the task manager says this leaves an instance of Excel running. What am I missing? Thank you.



using Microsoft.Office.Interop.Excel;
//Stuff...
// Launch dialog picker that return path to Excel file, in string
// called excelTemplate
Microsoft.Office.Interop.Excel.Application xlTemp = new Microsoft.Office.Interop.Excel.Application();
Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
xlTemp.DisplayAlerts = false;

// Poke through individual sheets, get some info from them

workbook.Close();
xlTemp.Quit();






c# excel-interop






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 1:20









Aram Schiffman

1




1







  • 1




    Possible duplicate of Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?
    – mjwills
    Nov 13 '18 at 1:24










  • See also my comment at stackoverflow.com/questions/50927453/… .
    – mjwills
    Nov 13 '18 at 1:24










  • It occurred to me that the search through the worksheets probably leaves it on a different worksheet than when it opened, but DisplayAlerts = false would suppress the "do you want to save" box.... So I tried adding object misValue = System.Reflection.Missing.Value; and specifying workbook.Close(false, misValue, misValue); That did not help.
    – Aram Schiffman
    Nov 13 '18 at 1:35










  • Excel Interop was designed to make developers hate their lives. I recommend checking out EPPlus. You don't need an open instance of Excel running to open a spreadsheet and read it. You don't even need Excel installed. You just open it like a document and read what you want. github.com/JanKallman/EPPlus
    – Scott Hannen
    Nov 13 '18 at 2:25












  • 1




    Possible duplicate of Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?
    – mjwills
    Nov 13 '18 at 1:24










  • See also my comment at stackoverflow.com/questions/50927453/… .
    – mjwills
    Nov 13 '18 at 1:24










  • It occurred to me that the search through the worksheets probably leaves it on a different worksheet than when it opened, but DisplayAlerts = false would suppress the "do you want to save" box.... So I tried adding object misValue = System.Reflection.Missing.Value; and specifying workbook.Close(false, misValue, misValue); That did not help.
    – Aram Schiffman
    Nov 13 '18 at 1:35










  • Excel Interop was designed to make developers hate their lives. I recommend checking out EPPlus. You don't need an open instance of Excel running to open a spreadsheet and read it. You don't even need Excel installed. You just open it like a document and read what you want. github.com/JanKallman/EPPlus
    – Scott Hannen
    Nov 13 '18 at 2:25







1




1




Possible duplicate of Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?
– mjwills
Nov 13 '18 at 1:24




Possible duplicate of Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?
– mjwills
Nov 13 '18 at 1:24












See also my comment at stackoverflow.com/questions/50927453/… .
– mjwills
Nov 13 '18 at 1:24




See also my comment at stackoverflow.com/questions/50927453/… .
– mjwills
Nov 13 '18 at 1:24












It occurred to me that the search through the worksheets probably leaves it on a different worksheet than when it opened, but DisplayAlerts = false would suppress the "do you want to save" box.... So I tried adding object misValue = System.Reflection.Missing.Value; and specifying workbook.Close(false, misValue, misValue); That did not help.
– Aram Schiffman
Nov 13 '18 at 1:35




It occurred to me that the search through the worksheets probably leaves it on a different worksheet than when it opened, but DisplayAlerts = false would suppress the "do you want to save" box.... So I tried adding object misValue = System.Reflection.Missing.Value; and specifying workbook.Close(false, misValue, misValue); That did not help.
– Aram Schiffman
Nov 13 '18 at 1:35












Excel Interop was designed to make developers hate their lives. I recommend checking out EPPlus. You don't need an open instance of Excel running to open a spreadsheet and read it. You don't even need Excel installed. You just open it like a document and read what you want. github.com/JanKallman/EPPlus
– Scott Hannen
Nov 13 '18 at 2:25




Excel Interop was designed to make developers hate their lives. I recommend checking out EPPlus. You don't need an open instance of Excel running to open a spreadsheet and read it. You don't even need Excel installed. You just open it like a document and read what you want. github.com/JanKallman/EPPlus
– Scott Hannen
Nov 13 '18 at 2:25












3 Answers
3






active

oldest

votes


















0














Application xlTemp = new Application();
Workbooks workbooks = xlTemp.Workbooks;
Workbook workbook = workbooks.Open(excelTemplate);

// Do stuff.

workbook.Close();
Marshal.ReleaseComObject(workbook);
Marshal.ReleaseComObject(workbooks);
xlTemp.Quit();
Marshal.ReleaseComObject(xlTemp);


Aside from needing to release each COM object, note also that by doing xlTemp.Workbooks.Open, you're leaking a COM reference by not assigning xlTemp.Workbooks to a variable that can be released later.






share|improve this answer
















  • 1




    How does that differ from the duplicate?
    – mjwills
    Nov 13 '18 at 1:31


















-1














You can used #using to automatically dispose the application.



using(Microsoft.Office.Interop.Excel.Application xlTemp = new 
Microsoft.Office.Interop.Excel.Application())

Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
xlTemp.DisplayAlerts = false;

// Poke through individual sheets, get some info from them

workbook.Close();






share|improve this answer




























    -2














    pls follow this link
    Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?



    and read this link
    https://social.msdn.microsoft.com/Forums/en-US/3cd1ac57-37ab-45e9-918b-7b253052c836/problem-in-closing-the-excelexe-which-is-opened-by-c?forum=csharplanguage






    share|improve this answer




















    • meta.stackexchange.com/questions/8231/…
      – Selvin
      Nov 13 '18 at 1:47










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272412%2fexcel-interop-lingering-instances-of-excel%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Application xlTemp = new Application();
    Workbooks workbooks = xlTemp.Workbooks;
    Workbook workbook = workbooks.Open(excelTemplate);

    // Do stuff.

    workbook.Close();
    Marshal.ReleaseComObject(workbook);
    Marshal.ReleaseComObject(workbooks);
    xlTemp.Quit();
    Marshal.ReleaseComObject(xlTemp);


    Aside from needing to release each COM object, note also that by doing xlTemp.Workbooks.Open, you're leaking a COM reference by not assigning xlTemp.Workbooks to a variable that can be released later.






    share|improve this answer
















    • 1




      How does that differ from the duplicate?
      – mjwills
      Nov 13 '18 at 1:31















    0














    Application xlTemp = new Application();
    Workbooks workbooks = xlTemp.Workbooks;
    Workbook workbook = workbooks.Open(excelTemplate);

    // Do stuff.

    workbook.Close();
    Marshal.ReleaseComObject(workbook);
    Marshal.ReleaseComObject(workbooks);
    xlTemp.Quit();
    Marshal.ReleaseComObject(xlTemp);


    Aside from needing to release each COM object, note also that by doing xlTemp.Workbooks.Open, you're leaking a COM reference by not assigning xlTemp.Workbooks to a variable that can be released later.






    share|improve this answer
















    • 1




      How does that differ from the duplicate?
      – mjwills
      Nov 13 '18 at 1:31













    0












    0








    0






    Application xlTemp = new Application();
    Workbooks workbooks = xlTemp.Workbooks;
    Workbook workbook = workbooks.Open(excelTemplate);

    // Do stuff.

    workbook.Close();
    Marshal.ReleaseComObject(workbook);
    Marshal.ReleaseComObject(workbooks);
    xlTemp.Quit();
    Marshal.ReleaseComObject(xlTemp);


    Aside from needing to release each COM object, note also that by doing xlTemp.Workbooks.Open, you're leaking a COM reference by not assigning xlTemp.Workbooks to a variable that can be released later.






    share|improve this answer












    Application xlTemp = new Application();
    Workbooks workbooks = xlTemp.Workbooks;
    Workbook workbook = workbooks.Open(excelTemplate);

    // Do stuff.

    workbook.Close();
    Marshal.ReleaseComObject(workbook);
    Marshal.ReleaseComObject(workbooks);
    xlTemp.Quit();
    Marshal.ReleaseComObject(xlTemp);


    Aside from needing to release each COM object, note also that by doing xlTemp.Workbooks.Open, you're leaking a COM reference by not assigning xlTemp.Workbooks to a variable that can be released later.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 1:28









    Justin

    405717




    405717







    • 1




      How does that differ from the duplicate?
      – mjwills
      Nov 13 '18 at 1:31












    • 1




      How does that differ from the duplicate?
      – mjwills
      Nov 13 '18 at 1:31







    1




    1




    How does that differ from the duplicate?
    – mjwills
    Nov 13 '18 at 1:31




    How does that differ from the duplicate?
    – mjwills
    Nov 13 '18 at 1:31













    -1














    You can used #using to automatically dispose the application.



    using(Microsoft.Office.Interop.Excel.Application xlTemp = new 
    Microsoft.Office.Interop.Excel.Application())

    Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
    xlTemp.DisplayAlerts = false;

    // Poke through individual sheets, get some info from them

    workbook.Close();






    share|improve this answer

























      -1














      You can used #using to automatically dispose the application.



      using(Microsoft.Office.Interop.Excel.Application xlTemp = new 
      Microsoft.Office.Interop.Excel.Application())

      Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
      xlTemp.DisplayAlerts = false;

      // Poke through individual sheets, get some info from them

      workbook.Close();






      share|improve this answer























        -1












        -1








        -1






        You can used #using to automatically dispose the application.



        using(Microsoft.Office.Interop.Excel.Application xlTemp = new 
        Microsoft.Office.Interop.Excel.Application())

        Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
        xlTemp.DisplayAlerts = false;

        // Poke through individual sheets, get some info from them

        workbook.Close();






        share|improve this answer












        You can used #using to automatically dispose the application.



        using(Microsoft.Office.Interop.Excel.Application xlTemp = new 
        Microsoft.Office.Interop.Excel.Application())

        Workbook workbook = xlTemp.Workbooks.Open(excelTemplate);
        xlTemp.DisplayAlerts = false;

        // Poke through individual sheets, get some info from them

        workbook.Close();







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 1:27









        Tuan Zaidi

        300111




        300111





















            -2














            pls follow this link
            Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?



            and read this link
            https://social.msdn.microsoft.com/Forums/en-US/3cd1ac57-37ab-45e9-918b-7b253052c836/problem-in-closing-the-excelexe-which-is-opened-by-c?forum=csharplanguage






            share|improve this answer




















            • meta.stackexchange.com/questions/8231/…
              – Selvin
              Nov 13 '18 at 1:47















            -2














            pls follow this link
            Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?



            and read this link
            https://social.msdn.microsoft.com/Forums/en-US/3cd1ac57-37ab-45e9-918b-7b253052c836/problem-in-closing-the-excelexe-which-is-opened-by-c?forum=csharplanguage






            share|improve this answer




















            • meta.stackexchange.com/questions/8231/…
              – Selvin
              Nov 13 '18 at 1:47













            -2












            -2








            -2






            pls follow this link
            Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?



            and read this link
            https://social.msdn.microsoft.com/Forums/en-US/3cd1ac57-37ab-45e9-918b-7b253052c836/problem-in-closing-the-excelexe-which-is-opened-by-c?forum=csharplanguage






            share|improve this answer












            pls follow this link
            Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?



            and read this link
            https://social.msdn.microsoft.com/Forums/en-US/3cd1ac57-37ab-45e9-918b-7b253052c836/problem-in-closing-the-excelexe-which-is-opened-by-c?forum=csharplanguage







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 13 '18 at 1:40









            Mahfuz Morshed

            5517




            5517











            • meta.stackexchange.com/questions/8231/…
              – Selvin
              Nov 13 '18 at 1:47
















            • meta.stackexchange.com/questions/8231/…
              – Selvin
              Nov 13 '18 at 1:47















            meta.stackexchange.com/questions/8231/…
            – Selvin
            Nov 13 '18 at 1:47




            meta.stackexchange.com/questions/8231/…
            – Selvin
            Nov 13 '18 at 1:47

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272412%2fexcel-interop-lingering-instances-of-excel%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党