MATLAB Answers

Reading from Multiple files & Multiple sheets

조회 수: 16(최근 30일)
Unnikrishnan PC
Unnikrishnan PC 26 Jun 2013
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-----------------
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

  댓글 수: 0

로그인 to comment.

채택된 답변

Tom 26 Jun 2013
for n = length(fileNames) %fileNames is a cell array of filenames
Book = Ex.workbooks.Open(fileNames{n});
for m = 1:length(sheetNames) % cell array of the 9 sheets
Sheet = Book.Sheets.Item(m);
%read from the sheets...
Book.Close %close workbook

  댓글 수: 1

Unnikrishnan PC
Unnikrishnan PC 26 Jun 2013
Thank you for the help

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by