How to combine multiple sheet in an excel file in to a single sheey

9 ビュー (過去 30 日間)
Srikant Sekar
Srikant Sekar 2021 年 9 月 3 日
コメント済み: Ive J 2021 年 9 月 4 日
I have an excel file with multiple sheets. Each sheet has single column and 350-450 row data. Around 80-95 sheets were there.How to bring all the column in sheets in to a single sheet? i need the name of each sheet to come as header in the final compiled sheet.am a beginner. Plz do help.

採用された回答

Ive J
Ive J 2021 年 9 月 3 日
Follow this example:
file = "test.xlsx"; % replace your file name
names = sheetnames(file);
data = table;
for i = 1:numel(names)
data.(names(i)) = readmatrix(file, 'Sheet', names(i));
end
writetable(data, 'merged.xlsx')
Note it works for your case: one numeric column per each data sheet.
  2 件のコメント
Srikant Sekar
Srikant Sekar 2021 年 9 月 4 日
Thank you so much for helping . an error mesg is coming as :Undefined function or variable 'sheetname'."
Ive J
Ive J 2021 年 9 月 4 日
Are you sure you type the correct function name? it's sheetnames. Aslo what version of MATLAB do you use? sheetnames was introduced in R2019b. In case your MATLAB is older, you can use actxserver :
exl = actxserver('excel.application');
exlWkbk = exl.Workbooks;
exlFile = exlWkbk.Open(fullfile(pwd,'test.xlsx'));
nSheets = exlFile.Sheets.Count;
names = strings(nSheets, 1);
for i = 1:nSheets
names(i) = exlFile.Sheets.Item(i).Name; % sheet names
end
Quit(exl)
delete(exl)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by