Read multiple excel file and write into single excel file

조회 수: 4 (최근 30일)
Zaki Ikhsan
Zaki Ikhsan 2016년 1월 6일
댓글: Zaki Ikhsan 2016년 1월 6일
Hi and very good day,
I do have a 100 of excel files and save as thermo1.xls, thermo2.xls......thermo100.xls. Each of the files consist of a row and 20 columns of data on the single sheet (it write on A1 to T1).
The thing that i need to do is, to write all of the data (A1:T1 on thermo1.xls, A1:T1 on thermo2.xls.....) into a single sheet on a new single excel file (it might be saved as finalthermo.xls).
thus, finally the data will be sort (on finalthermo.xls) as (A1:T1 from thermo1.xls, A2:T2 from thermo2.xls......A100:T100 from thermo100.xls)
At the moment, i wrote this code by it wont happen as i wish, all entire row and column were overwrite with data from the last file (thermo100.xls)
source_dir = 'C:\Users\sourcedir.....' %my file source dir
dest_dir = 'C:\Users\destdir.......' %my file dest dir
source_files = dir(fullfile(source_dir, '*.xls'));
for i = 1:length(source_files)
data = xlsread(fullfile(source_dir, source_files(i).name));
for k =1:100
xlswrite('finalthermo.xls',data, 1, sprintf('A%d',(k+1)-1));
end
end
I looking forward for somebody to help me fixing the coding...
thank you.

채택된 답변

Renato Agurto
Renato Agurto 2016년 1월 6일
hello
you can try this.
source_dir = 'C:\Users\sourcedir.....' %my file source dir
dest_dir = 'C:\Users\destdir.......' %my file dest dir
source_files = dir(fullfile(source_dir, '*.xls'));
data = zeros(100,20)
for i = 1:length(source_files)
data(i,:) = xlsread(fullfile(source_dir, source_files(i).name));
%or to make sure you only read one line
%data(i,:) = xlsread(fullfile(source_dir, source_files(i).name),1,'A1:T1');
end
xlswrite('finalthermo.xls',data);
  댓글 수: 1
Zaki Ikhsan
Zaki Ikhsan 2016년 1월 6일
Hello Renato
I run on your code, thank you very much, it works perfectly! :) appreciate it.
Upvote and thumbs up for you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by