Reading from Multiple files & Multiple sheets
조회 수: 2 (최근 30일)
이전 댓글 표시
I have 60 excel files named 1,2 ...60 and each file consists of 9 sheets(Same name). I have to read from these files and consolidate in another file. Can you please help me to do this operation by looping. see the code below. Can someone suggest an easier way to read sheet names by looping and getting sheet names from an array? Is it possible. Similarly can I get workbook names from an array?
exwb1 = ex.Workbooks.Open('C:\Advisory\1.xls');
exwb44 = ex.Workbooks.Open('C:\Advisory\Target.xls');
%-------------------Open WorkSheets in Workbooks-----------------
exSheet1=exwb1.Sheets.Item('Dip1');
exSheet2=exwb2.Sheets.Item('Dip2 EPE');
exSheet3=exwb3.Sheets.Item('Dip2 ECE');
exSheet4=exwb4.Sheets.Item('Dip2 ME');
exSheet5=exwb5.Sheets.Item('Dip2 Arch');
exSheet6=exwb6.Sheets.Item('Dip2 QS');
exSheet7=exwb7.Sheets.Item('AD EPE');
exSheet8=exwb8.Sheets.Item('AD ECE');
exSheet9=exwb9.Sheets.Item('AD ME');
%Output File
exSheet44=exwb44.Sheets.Item('Sheet1');
댓글 수: 0
채택된 답변
Tom
2013년 6월 26일
for n = length(fileNames) %fileNames is a cell array of filenames
Book = Ex.workbooks.Open(fileNames{n});
Book.Activate;
for m = 1:length(sheetNames) % cell array of the 9 sheets
Sheet = Book.Sheets.Item(m);
%read from the sheets...
end
Book.Close %close workbook
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!