Compiling excel files from subfiles
    조회 수: 2 (최근 30일)
  
       이전 댓글 표시
    
I have 200 excel files, each in their own subfolder of one big folder. They need to be compiled into one master excel sheet. How can i identify the excel sheets in the subfolders and put them into one big excel sheet?
Each excel sheet is named differently but all have "-inflection" at the end of the name. 
Thank you!
댓글 수: 0
채택된 답변
  Gareth
      
 2019년 2월 27일
        There might be a more elegant way than what I am proposing but this should work:
ds = spreadsheetDatastore(pwd,'IncludeSubfolders',true);
ds.Files = ds.Files(contains(ds.Files,'inflection'));
ds.readall();
This way you can use string manipulation to choose which files you want the DataStore to use. Probaly you can also do this in the creation of the ds.
댓글 수: 7
  Gareth
      
 2019년 3월 5일
				ds = spreadsheetDatastore(pwd,'IncludeSubfolders',true);
idx = [];
for i = 1:length(ds.Files)
    if strfind(ds.Files{i},'Copy')
        idx = [idx;i];
    end
end
out = table();
for i = 1:length(ds.Files)
   data = ds.read();
   filepath = fileparts(ds.Files{i});
   data.folder = repmat({filepath},height(data),1);
   out = [out;data];
end
out
추가 답변 (2개)
  Gareth
      
 2019년 2월 25일
        I am using R2018b, and there is a wonderful datatype: datastore which does this for you. A variation of it is the spreadsheetdatastore.
if you do something like:
ds = datastore('*inflection*.xlsx');
mydata = ds.readall();
writetable(mydata,'mymasterexcelfile.xlsx');
This should give you what you are looking for. I would spend sometime looking at datastores and the spreadsheetdatastore as they are both very useful comands.
  Gareth
      
 2019년 2월 25일
        Try the following:
ds = spreadsheetDatastore(pwd,'IncludeSubfolders',true)
where pwd is the root folder.
참고 항목
카테고리
				Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

