Reading specific range from multiple sheets in Excel
5 ビュー (過去 30 日間)
古いコメントを表示
Hi there, Hope all is well. Ive been looking for a clear method on how to read a specific range for several Excel sheets. For example: I have this line:
T = xlsread ('myExcel.xlsx', 'sheet', 'N2:N30')
I want the 'sheet' to be from several sheets not only one. I have come across this code:
alldata = cell(1, m);
for(i=1:1:m); Sheet = char(sheetname(1,i));
alldata{i} = xlsread('test', Sheet);
end
But I could not get it. Can you please elaborate?
Thank you
0 件のコメント
採用された回答
dpb
2016 年 12 月 13 日
編集済み: dpb
2016 年 12 月 13 日
Use xlsfinfo to return the list of sheets in the workbook and iterate over the returned cellstr array..
excFile='myExcel.xlsx'; % Excel file of interest
rnge='N2:N30'; % desired range
[stat,sheets]=xlsfinfo(excFile); % get status, sheet(s) in workbook
if isempty(stat),error('bad Excel file format'),end % check status
for sht=sheets % iterate over 1xn array as column
T=xlsread(excFile,sht,rnge); % read each sheet, range in turn...
% Must do whatever with T here before reading next sheet...store or whatever
....
end
This will be slow because xlsread opens/closes the file every read operation. There's a FileExchange submittal that can do it without that overhead...but I don't have a direct link to it at hand, sorry.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!