Execute files from listbox one by one

6 Ansichten (letzte 30 Tage)
Ghenji
Ghenji am 12 Feb. 2018
Beantwortet: Ghenji am 2 Mär. 2018
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 Kommentare
Ghenji
Ghenji am 12 Feb. 2018
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 am 12 Feb. 2018
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')};

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ghenji
Ghenji am 2 Mär. 2018
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')};

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by