我试过了:
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();
但它不会终止excel应用程序(我仍然在任务管理器中看到它)。 试一试,我想做一些像
这样的事情workbook_instance = NULL;
但不接受。 有什么建议吗? 谢谢。
答案 0 :(得分:0)
谢谢@amaldev
根据从第一个链接收集的一些想法,我成功了
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();