Write multiple excel files into one excel workbook sheet by sheet.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ojo Olusola
am 7 Aug. 2021
Kommentiert: Ojo Olusola
am 8 Aug. 2021
I have 40 excel files (.xlsx') with different names in a folder on desktop. I want to write them into one excel workbook named 'mydata.xlsx' containing 40 sheets with each sheet bear the names of each of the files. Kindly help me with the codes. Thanks.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Aug. 2021
Bearbeitet: Walter Roberson
am 7 Aug. 2021
outfile = 'mydata.xlsx';
dinfo = dir('*.xlsx');
filenames = setdiff({dinfo.name}, outfile);
for K = 1 : length(filenames)
thisfile = filenames{K};
[~, basename, ~] = fileparts(thisfile);
T = readtable(thisfile);
writetable(T, outfile, 'sheet', basename);
end
5 Kommentare
Walter Roberson
am 7 Aug. 2021
Bearbeitet: Walter Roberson
am 7 Aug. 2021
l guess it is because we use readtable and writetable.
That seems unlikely to be the reason, but you can try xlsread() / xlswrite() anyhow.
outfile = 'mydata.xlsx';
dinfo = dir('*.xlsx');
filenames = setdiff({dinfo.name}, outfile);
for K = 1 : length(filenames)
thisfile = filenames{K};
[~, basename, ~] = fileparts(thisfile);
[~, ~, raw] = xlsread(thisfile);
xlswrite(outfile, raw, basename);
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!