How to merge multiple xls files into a single file with the same worksheet?
1 回表示 (過去 30 日間)
古いコメントを表示
Kasih Ditaningtyas Sari Pratiwi
2017 年 11 月 11 日
コメント済み: Kasih Ditaningtyas Sari Pratiwi
2017 年 11 月 12 日
Hi. I want to ask about how to merge multiple xls files into a single file with the same worksheet. I read some questions which also have the same problem, but mostly the resulted file has separate worksheets. In my case, I want to merge the table so that it only has one worksheet. I try this code below:
[files,folder] = uigetfile('*.xls','Select Files','MultiSelect','on');
output = fullfile(folder,'rainfall.xls');
addpath(dir);
for i = 1:numel(files)
ftab = readtable(files{i});
writetable(ftab,output,'Sheet',files{i});
end
but of course it has separated worksheets. I want to make it in one worksheet as the files have also the same structure so it should be easily to merge. Could you please help me? I really appreciate for your help.
0 件のコメント
回答 (1 件)
dpb
2017 年 11 月 12 日
Probably simplest presuming the individual sheets aren't terribly big is to loop through and accumulate all the data into one array and then write it at the end to the target worksheet. This is minimum number of nFiles reads and one write.
Otherwise, to do sequentially you'll have to keep track of location in the sheet to write each subsequent dataset to and it's both nFiles reads and writes.
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!