Reading specific range from multiple sheets in Excel
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andere
el 12 de Dic. de 2016
Comentada: Andere
el 13 de Dic. de 2016
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 comentarios
Respuesta aceptada
dpb
el 13 de Dic. de 2016
Editada: dpb
el 13 de Dic. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!