How to merge multiple xls files into a single file with the same worksheet?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Kasih Ditaningtyas Sari Pratiwi
el 11 de Nov. de 2017
Comentada: Kasih Ditaningtyas Sari Pratiwi
el 12 de Nov. de 2017
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 comentarios
Respuestas (1)
dpb
el 12 de Nov. de 2017
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.
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!