这是一个工作的 Matlab 文件,应该可以满足您的要求:
exl = actxserver('excel.application');
exlWkbk = exl.Workbooks;
exlFile = exlWkbk.Open(['C:\mypath\ExcelCOM.xls']);
exlSheet1 = exlFile.Sheets.Item('Sheet1');
robj = exlSheet1.Columns.End(4); % Find the end of the column
numrows = robj.row; % And determine what row it is
dat_range = ['D2:G' num2str(numrows)]; % Read to the last row
rngObj = exlSheet1.Range(dat_range);
exlData = rngObj.Value;
for ii = 1:size(exlData,2)
matData(:,ii) = reshape([exlData{2:end,ii}],size(exlData(2:end,ii)));
lBoxList{ii} = [exlData{1,ii}];
end
exl.visible = true;
for j=1:size(exlData,2)
for k=1:13
A(k+2,j)=0
A(k,j)=matData(k,j)
end
end
exlWkbk.Close
exl.Quit