How can i compile many excel (xls) files in one

2 views (last 30 days)
I have 100 excel (.xls) files, everyone with 1 sheet , but i need to compile all these files in only one excel file with 100 sheets .
Can anyone help me? Please
Thank you :)
(sorry if my english isn't perfect)

Accepted Answer

Image Analyst
Image Analyst on 28 Feb 2015
Luis
Depends on what version of Excel you have. With Excel 2003 and earlier you are limited to 32 worksheets. It's more for later versions but I'm not sure of the limit. Anyway to do this quickly you need to use ActiveX programming. You open Excel once, open an output workbook once, and then open each input workbook and transfer the data to a new worksheet. Then save the output workbook and Quit Excel. I've attached a demo that you can easily modify.
If that's way over your head and you don't want to learn it, then you can call xlsread and xlswrite a hundred times, but it will take forever.
See the FAQ for how to loop over the sequence of file names: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
  3 Comments
Image Analyst
Image Analyst on 28 Feb 2015
Did you look at the FAQ? You just add them into the loop
myFolder = 'C:\Documents and Settings\yourUserName\My Documents\My Pictures';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.xls');
xlsFiles = dir(filePattern);
for k = 1:length(xlsFiles)
baseFileName = xlsFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
[~, ~, raw] = xlsread(fullFileName);
sheetName = sprintf('Sheet%d', k);
xlswrite(outputFileName, raw, sheetName);
end
or something like that. Might require a little debugging. Of course you need to specify the output filename. This method will take a long time compared to ActiveX so you should learn ActiveX and use that instead - I gave you a demo for it.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!