0

I have tried:

while (System::Runtime::InteropServices::Marshal::ReleaseComObject(worksheet_instance) > 0) ;
workbook_instance->Close(true, "Dummy.xlsx", Missing::Value);
while (System::Runtime::InteropServices::Marshal::ReleaseComObject(workbook_instance) > 0) ;
workbook_instance->~Workbook();
exApp_instance->Quit();
exApp_instance->~Application();

But it does not terminate the excel application (I still see it in the task manager). As a try, I would like to do something like

workbook_instance = NULL; 

but it is not accepted. Any suggestion? Thank you.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Angel
  • 11
  • 1
  • Please refer the links below. Although it's in C#, you will get an idea. [How to properly clean up Excel interop objects in C#](http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c-sharp) [How do you close Excel com object and save the work?](http://stackoverflow.com/questions/686789/how-do-you-close-excel-com-object-and-save-the-work) – Amal Dev Aug 29 '12 at 06:39

1 Answers1

1

Thank you @amaldev
According to some ideas collected from the first link, I succeeded with

try{
    while (System::Runtime::InteropServices::Marshal::ReleaseComObject(ws) > 0) ; 
} catch(...) {} 

wb->Close(false, Missing::Value, Missing::Value); 
try { 
    while (System::Runtime::InteropServices::Marshal::ReleaseComObject(wb) > 0) ; 
} catch(...) {} 

exApp->Quit(); 
try { 
    while (System::Runtime::InteropServices::Marshal::ReleaseComObject(exApp) > 0) ; 
} 
catch(...) {} 

System::GC::Collect(); 
System::GC::WaitForPendingFinalizers();
Angel
  • 11
  • 1