Upload excel data to uitable

4 views (last 30 days)
Daniel Kin
Daniel Kin on 9 Apr 2013
Commented: Malte Räuchle on 23 Jul 2020
I wish to create a push button that read an excel file (always 7 columns) and transfer its contact to a uitable (with 7 columns), include showing the data in the uitable. I was thinking and looking for a solution how to so without success. Can it be done?
function readData_Callback(hObject, eventdata, handles)
handles.output = hObject;
[file,path] = uigetfile({'*.xls;*.xlsx','Excel Files'},' Select data file')
filename = strcat(path,file);
set(handles.readData);
data = xlsread(filename);
  1 Comment
Daniel Kin
Daniel Kin on 10 Apr 2013
Solved it:
function readData_Callback(hObject, eventdata, handles)
% hObject handle to readData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.output = hObject;
[file,path] = uigetfile({'*.xls;*.xlsx','Excel Files'},' Select data file')
filename = strcat(path,file);
set(handles.readData);
data = xlsread(filename);
data(:,[1 7])
set(handles.uitableData, 'Data',data);

Sign in to comment.

Answers (1)

brigitte duran
brigitte duran on 14 Apr 2016
hello, sorry but your code doesn't work...I am looking for a solution but without success...My code is: In my GUI file.m:
% --- Executes when entered data in editable cell(s) in uitable1.
function uitable1_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
% handles.output = hObject;
[file,path] = uigetfile({'*.xls;*.xlsx','Excel Files'},'FluidesInternes');
filename = strcat(path,file);
%set(handles.upload);
data = xlsread(filename);
set(handles.uitable1,'Data',data)
  1 Comment
Malte Räuchle
Malte Räuchle on 23 Jul 2020
Is it possible that your Excel File contains any other type than numeric array, logical array, or cell array?

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!