Matlab Actxserver:我怎样才能终止由matlab中的actxserver打开的进程

我想在MATLAB中打开和closures一个Excel文件。 我已经尝试了下面的代码 ,但它closures与actxserver进程失败

h.WorkBooks.Item(wbkname).Close; 

这里是我的代码这个问题,我怎样才能终止的Excel文件?

 .Quit .delete 

我也尝试通过VBA子模块来closuresexcel文件,但它给了我一个错误信息:

 fullFileName = [pwd '\KOSPI200_1월.xlsm']; excel = actxserver('Excel.Application'); file = excel.Workbooks.Open(fullFileName); excel.Run('jongho_bot_initial'); excel.Run('jongho_bot_loop',2); 

这里是一个例子,它创build一个新的电子表格,写入一些值,保存文件并退出。 Excel进程在最后被干净地终止。

 % create Excel COM server excel = actxserver('Excel.Application'); excel.Visible = true; % make the window visible % create new workbook wb = excel.Workbooks.Add(); % get "Sheet1" and activate it sheet = wb.Sheets.Item(1); sheet.Activate(); % select a 5x5 range, and fill it with some numeric values sheet.Range('A1:E5').Value = num2cell(magic(5)); % save spreadsheet file excel.DisplayAlerts = false; % overwrite file without prompts wb.SaveAs(fullfile(pwd(),'myfile.xlsx')); % close spreadsheet wb.Close(false); % quit Excel excel.Quit(); % delete handles and clear variables delete(excel); clear sheet wb excel 

如果您希望在后台执行自动化而无需用户交互,您可能还需要适当地设置某些属性 :

 excel.Visible = false; % invisible Excel window excel.ScreenUpdating = false; % turn off screen update to run faster excel.Interactive = false; % non-interactive mode, with no keyboard/mouse excel.DisplayAlerts = false; % no prompts or alert messages excel.UserControl = false; % object freed when reference count reaches zero