How to read and write multiple excel sheets in Matlab?
Show older comments
Hi everyone,
I have an excel file with 31 sheets. Sheets names are as default from 01, 02, 03, ...., 31. How can I read multiple sheets in Matlab and write them in the same sheet with an order? in1 = xlsread('INPUT',1,'c7:c31'); in2 = xlsread('INPUT',2,'c7:c31'); in3 = xlsread('INPUT',3,'c7:c31'); in4 = xlsread('INPUT',4,'c7:c31'); in5 = xlsread('INPUT',5,'c7:c31'); in6 = xlsread('INPUT',6,'c7:c31'); in7 = xlsread('INPUT',7,'c7:c31'); in8 = xlsread('INPUT',8,'c7:c31'); %in9 %in10 %.........
xlswrite('INPUT',in1,35,'B1:B24'); xlswrite('INPUT',in2,35,'B25:B48'); xlswrite('INPUT',in3,35,'B49:B72'); xlswrite('INPUT',in4,35,'B73:B96'); xlswrite('INPUT',in5,35,'B97:B120'); xlswrite('INPUT',in6,35,'B121:B144'); xlswrite('INPUT',in7,35,'B145:B168'); xlswrite('INPUT',in8,35,'B169:B182');
Answers (1)
Bob Thompson
on 9 Aug 2018
0 votes
xlsread() and xlswrite() are only capable of using one sheet at a time. To examine multiple sheets, the commands must be called the same number of times as number of sheets. This can be done independently as you have shown in your sample, or by means of a loop.
Alternatively, the use of the ActXServer will allow you to interface more directly with excel, and allows for the opening of a workbook in its entirety, so that multiple sheets can be called. Check out the answers posted here: https://www.mathworks.com/matlabcentral/answers/16299-is-there-instead-solution-of-xlsread
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!