盡管MATLAB帶有高級(jí)的Office交互接口(xlsread/xlswrite等),但是對(duì)于高級(jí)的應(yīng)用仍不能滿足拄显,且慢的難以忍受。因此涩笤,使用MATLAB的ActiveX調(diào)用成了最佳配合
創(chuàng)建ActiveX對(duì)象
try
h = actxGetRunningServer('Excel.Application');
if(h.Visible) , error 'not actx'; end
catch
try
h = actxserver('Excel.Application');
% config
h.Visible = false; % invisible Excel window
h.ScreenUpdating = false; % turn off screen update to run faster
h.Interactive = false; % non-interactive mode, with no keyboard/mouse
h.DisplayAlerts = false; % no prompts or alert messages
%h.UserControl = false; % object freed when reference count reaches zero
catch
h = [];
end
end
操作工作表
r = h.Workbooks;
t = h.wb.Open(‘1.xlsx’);
t.Range('A1').Value = ‘hello’;
t.Range('A1').Borders.Color = 500;
t.Activate;
t.SaveAs(xlsf);
t.Close;
退出ActiveX對(duì)象
h.Quit
h.delete
更多函數(shù)使用說明
https://msdn.microsoft.com/zh-cn/vba/excel-vba/articles/object-model-excel-vba-reference