我在同一个目录中有很多excel文件...每个excel文件里面都有几张表...
我是否知道如何将所有excel文件中的所有工作表收集到新的Excel文件中?
names=dir('*.xls');
names={names.name};
output='out.xls';
for i=1:length(names)
z = xlsread(names{i});
xlswrite(output,z);
end
保持错误。任何人都可以提供帮助?!
答案 0 :(得分:0)
以下是一种可能的实施方式:
%# get all XLS files in source directory
dirName = '.\in';
files = dir( fullfile(dirName,'*.xls') );
files = {files.name}'; %'
%# for each input file
for i=1:numel(files)
fname = fullfile(dirName, files{i}); %# absolute-path filename
[~,f] = fileparts(fname); %# used to name sheets in output
%# loop over each sheet in input file
[~,sheets] = xlsfinfo(fname);
for s=1:numel(sheets)
%# read content
[~,~,rawData] = xlsread(fname, sheets{s});
%# write to output file as new sheet
xlswrite('out.xls', rawData, [f '_' sheets{s}]);
end
end