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!