showing excel files in listbox(in gui) and opening these excel files from listbox.

2 ビュー (過去 30 日間)
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

採用された回答

Image Analyst
Image Analyst 2014 年 10 月 8 日
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
  2 件のコメント
Muhammad Hussain
Muhammad Hussain 2014 年 10 月 9 日
Thank you very much. Could you please tell me how to use winopen command so that it open the excel files now in the listbox1(by double click a file in listbox1).
Image Analyst
Image Analyst 2014 年 10 月 9 日
Try this:
% Get a list of indexes in the listbox that the user has selected.
Selected = get(handles.lstExcelFiles, 'Value');
% If more than one is selected, bail out.
if length(Selected) > 1
return;
end
% If you get to here, exactly 1 is selected.
% Now, get a list of all the items in the listbox.
ListOfFileNames = get(handles.lstExcelFiles, 'string');
% Get the name of the one particular file that has been selected.
baseFileName = strcat(cell2mat(ListOfFileNames(Selected)));
% Get the full file name by prepending the folder where the files live.
excelFullFileName= fullfile(folder, baseFileName);
% Open file in Excel.
winopen(excelFullFileName);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by