xlsread multiple files from multiple folders
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(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!