Can I import multiple sheets from one excel file using for loop?

6 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Stephen23
Stephen23 il 3 Mar 2022
Modificato: Stephen23 il 3 Mar 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:

Più risposte (0)

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by