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

8 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2022-3-3
编辑:Stephen23 2022-3-3
"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:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by