Execute files from listbox one by one

1 回表示 (過去 30 日間)
Ghenji
Ghenji 2018 年 2 月 12 日
回答済み: Ghenji 2018 年 3 月 2 日
GUI load some files using Pushbutton1 inside Listbox1. Now i have got another pushbutton2 to select all the files populated in listbox1. Now I would like to read all data from the files in listbox1 one by one. callback for pushbutton3 should be such that it should get all the filenames from _ listbox1_ and read it individually. Some how am not able to do it. Do i need callback for listbox1 as well?
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[filename,pathname,filterindex] = uigetfile('*.xls;*.xlsx;*.xlsm;*.xlsb', 'Multiselect', 'on');
set(handles.listboxExcelfiles,'string',filename);
% --- Executes on selection change in listbox1
function listbox1_Callback(hObject, eventdata, handles)
% Hints: contents = cellstr(get(hObject,'String')) returns listboxDatasheets contents as cell array
% contents{get(hObject,'Value')} returns selected item from listboxDatasheets
% --- Executes on button press in pushbutton2
function pushbutton2_Callback(hObject, eventdata, handles)
select_all = numel(get(handles.listboxExcelfiles,'string'));
set(handles.listboxExcelfiles,'value',1:select_all);
% --- Executes on button press in pushbutton3
function pushbutton3_Callback(hObject, eventdata, handles)
filename = get(handles.listbox1,'string'));
len = length(filename);
for j = 1 : len
[num,txt,raw] = xlsread(filename,10,'J10:J34');
set(handles.listbox2, 'string', num);
end
Also there could be overwriting in listbox2. How can i exclude value if there is a repetition in listbox2
  3 件のコメント
Ghenji
Ghenji 2018 年 2 月 12 日
Thank you for your answer. I made few changes accordingly -
function pushbutton3_Callback(hObject, eventdata, handles)
listBoxitems = cellstr(get(handles.listbox1,'String'));
selectedstring = listBoxitems{get(handles.listbox1,'Value')};
len = length(selectedstring);
for j = 1 : len
[num,txt,raw] = xlsread(filename,10,'J10:J34');
set(handles.listbox2, 'string', num);
end
and am getting this error -
Error using Interface.000208DB_0000_0000_C000_000000000046/Open
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Sorry, we couldn't find Copy of BMI260 WMR V07-V09 Samples rev1.xlsm. Is it possible it was moved,
renamed or deleted?
Help File: xlmain11.chm
Help Context ID: 0
Error in colordefined>pushbuttonExtract_Callback (line 157)
workbook = excel.Workbooks.Open(selectedstring);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in colordefined (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)colordefined('pushbuttonExtract_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Ghenji
Ghenji 2018 年 2 月 12 日
well I was able to get answer to this. Problem was undefined path for the files. Needed following changes -
function pushbutton1_Callback(hObject, eventdata, handles)
[filename,pathname,filterindex] = uigetfile('*.xls;*.xlsx;*.xlsm;*.xlsb', 'Multiselect', 'on');
fullname = fullfile(pathname, filename);
set(handles.listboxExcelfiles,'string',fullname);
function pushbutton3_Callback(hObject, eventdata, handles)
listBoxItems = cellstr(get(handles.listboxExcelfiles,'String'));
selectedstring = listBoxItems{get(handles.listboxExcelfiles,'Value')};

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

採用された回答

Ghenji
Ghenji 2018 年 3 月 2 日
well I was able to get answer to this. Problem was undefined path for the files. Needed following changes -
[filename,pathname,filterindex] = uigetfile('*.xls;*.xlsx;*.xlsm;*.xlsb', 'Multiselect', 'on');
fullname = fullfile(pathname, filename);
set(handles.listboxExcelfiles,'string',fullname);
function pushbutton3_Callback(hObject, eventdata, handles)
listBoxItems = cellstr(get(handles.listboxExcelfiles,'String'));
selectedstring = listBoxItems{get(handles.listboxExcelfiles,'Value')};

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by