When using Excel as an ActiveX server, why does the excel.exe process still exist after I close Excel?
6 次查看(过去 30 天)
显示 更早的评论
When using Excel as an ActiveX server, I would like to know why the excel.exe process still exists after I close Excel.
I would like to know how the lingering Excel process that was created with actxserver can be terminated.
The following code uses ActiveX to open Excel, set values to a range, and close Excel. However, if I look under my Task Manager --> Processes, it still show that EXCEL.EXE exists. It is not taking any CPU time, but it is taking up memory.
Excel = actxserver('Excel.Application');
set(Excel, 'Visible', 1);
Workbooks = Excel.Workbooks;
Workbook = invoke(Workbooks, 'Add');
Sheets = Excel.ActiveWorkBook.Sheets;
sheet2 = get(Sheets, 'Item', 2);
invoke(sheet2, 'Activate');
Activesheet = Excel.Activesheet;
A = [1 2; 3 4];
ActivesheetRange = get(Activesheet,'Range','A1:B2');
set(ActivesheetRange, 'Value', A);
Range = get(Activesheet, 'Range', 'A1:B2');
B = Range.value;
B = reshape([B{:}], size(B));
invoke(Workbook, 'SaveAs', 'myfile.xls');
invoke(Excel, 'Quit');
采纳的回答
MathWorks Support Team
2010-3-11
To shut down Excel, which is the ActiveX server in this case, execute the RELEASE command with the ActiveX server object and all the interface handles. Note that all interface handles to the server object must be released in order for the server process to terminate.
For the code under 'Problem Description', following are the interface handles (in order of creation):
Workbooks
Workbook
Sheets
sheet2
Activesheet
ActivesheetRange
Range
The following lines of code must be appended to the original code in order for the Excel automation server process to terminate:
release(Range)
release(ActivesheetRange)
release(Activesheet)
release(sheet2)
release(Sheets)
release(Workbook)
release(Workbooks)
release(Excel)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!