Reading from Multiple files & Multiple sheets
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Tom
am 26 Jun. 2013
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!