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

8 ビュー (過去 30 日間)
Nicolas Kropff
Nicolas Kropff 2022 年 3 月 3 日
コメント済み: Nicolas Kropff 2022 年 3 月 3 日
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:
  1 件のコメント
Nicolas Kropff
Nicolas Kropff 2022 年 3 月 3 日
Great! Thanks a lot for the immediate response :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData 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