Can I import multiple sheets from one excel file using for loop?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nicolas Kropff
el 3 de Mzo. de 2022
Comentada: Nicolas Kropff
el 3 de Mzo. de 2022
Hi everyone,
I am currently trying to import multiple sheets from one excel file by coding a for-loop.
As the number of sheets within the source excel file might vary in the future, I am trying to consider this in my coding.
At the current state of the code shown below, the output table "T" only contains the imported values from the last sheet of the source excel file.
Is it possible to get different individual output tables equal to the number of sheets within the original excel file for further processing in MATLAB?
Thanks for your support.
sheets = sheetnames("Notenlisten_TEST.xlsx"); % identifying no. of sheets in single excel file
nsheets = numel(sheets); % to identify number of iterations
% Data Import
for iSheetData = 1:nsheets
T = readtable("Notenlisten_TEST.xlsx","Sheet",iSheetData);
end
0 comentarios
Respuesta aceptada
Stephen23
el 3 de Mzo. de 2022
Editada: Stephen23
el 3 de Mzo. de 2022
"Is it possible to get different individual output tables equal to the number of sheets within the original excel file for further processing in MATLAB? "
Of course, just store them in a container array, for example in a cell array:
F = "Notenlisten_TEST.xlsx";
S = sheetnames(F);
N = numel(S);
C = cell(1,N);
for k = 1:N
C{k} = readtable(F,"Sheet",S(k));
end
See also:
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!