0

我努力了:

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; 

但它不被接受。有什么建议吗?谢谢你。

4

1 回答 1

1

谢谢@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();
于 2012-08-31T10:36:24.907 回答