xlsread multiple files from multiple folders

조회 수: 3 (최근 30일)
Daniel Green
Daniel Green 2019년 8월 12일
I want to xlsread and xlswrite every .xls file within each folder from a group of folders (58 total folders).
This code works for one file:
f = dir('Y:\Projects\Round\test.xls')
sheet = 'Logic';
[num,str] = xlsread(f,sheet,'D5:D5');
n = 675;
if str == "Test"
xlRange = 'D1';
xlswrite(f,n,sheet,'D7:D7')
end
This is semi-finished code where I think it would work for one folder, but I want it to loop through every folder within a folder.
files = dir('Y:\Projects\Round\*.xls');
sheet = 'Logic';
nFiles = length(files);
for i = 1:nFiles
fName = files(i).name
[num,str] = xlsread(fName,sheet,'D5:D5');
sttd = 675;
if str == "Teset"
xlRange = 'D1';
xlswrite(fName,sttd,sheet,'D7:D7')
end
end
Problem with this code is that when I get the name of the file and put it into xlsread, it assumes I am working in my current folder and not somewhere else. instead of fName I need the whole directory.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by