MATLAB: Showing excel files in listbox(in gui) and opening these excel files from listbox.

showing excel files in listboxxlsread

Hi,I have made a gui,it has one push button and a listbox.By pushbutton,i am opening a folder in a directory(somewhere in my computer) and then opening subfolders in that folder and renaming a excel file in each subfolder with subfoldername.xlsx and storing it in the parent folder.Now I want to show each excel file(which i selected in subfolders and now it is in parent folder with a new name) in my listbox and from listbox I want to open this excel file.Please tell me how to do it.Thanks

Best Answer

Use the system command to launch Excel open to the filename you selected in the listbox. If you don't know how to load a listbox, see this function
% --- Load up the listbox with xls files in folder yourFolder
function handles = LoadListBox(handles)
try
yourFolder = 'C:/whatever';
% Load up the listbox.
ListOfFilenames = {};
dirListing = dir([yourFolder '/*.xls*']);
for Index = 1:length(dirListing)
baseFileName = dirListing(Index).name;
ListOfFilenames = [ListOfFilenames baseFileName];
end
set(handles.Listbox1, 'string', ListOfFilenames);
catch ME
errorMessage = sprintf('Error in LoadListBox().\nThe error reported by MATLAB is:\n\n%s', ME.message);
uiwait(warndlg(errorMessage));
end
return; % from LoadListBox