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 Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by