Reading specific range from multiple sheets in Excel
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
dpb
le 13 Déc 2016
Modifié(e) : dpb
le 13 Déc 2016
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!