MATLAB Answers

0

Reading from Multiple files & Multiple sheets

Unnikrishnan PC さんによって質問されました 2013 年 6 月 26 日
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 件のコメント

サインイン to comment.

製品

1 件の回答

Tom
回答者: 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

  1 件のコメント

Unnikrishnan PC 2013 年 6 月 26 日
Thank you for the help

サインイン to comment.



Translated by