Compiling excel files from subfiles
3 views (last 30 days)
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.
GT on 27 Feb 2019
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'));
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.
More Answers (2)
Hi Jen ,
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();
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.