Excel Interop, lingering instances of Excel
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
add a comment |
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
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
add a comment |
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
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
c# excel-interop
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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.
1
How does that differ from the duplicate?
– mjwills
Nov 13 '18 at 1:31
add a comment |
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();
add a comment |
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
meta.stackexchange.com/questions/8231/…
– Selvin
Nov 13 '18 at 1:47
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
1
How does that differ from the duplicate?
– mjwills
Nov 13 '18 at 1:31
add a comment |
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.
1
How does that differ from the duplicate?
– mjwills
Nov 13 '18 at 1:31
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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();
add a comment |
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();
add a comment |
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();
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();
answered Nov 13 '18 at 1:27
Tuan Zaidi
300111
300111
add a comment |
add a comment |
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
meta.stackexchange.com/questions/8231/…
– Selvin
Nov 13 '18 at 1:47
add a comment |
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
meta.stackexchange.com/questions/8231/…
– Selvin
Nov 13 '18 at 1:47
add a comment |
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
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
answered Nov 13 '18 at 1:40
Mahfuz Morshed
5517
5517
meta.stackexchange.com/questions/8231/…
– Selvin
Nov 13 '18 at 1:47
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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