How can I edit my Excel data in a UItable Gui?

조회 수: 2 (최근 30일)
brigitte duran
brigitte duran 2016년 4월 14일
답변: Orion 2016년 4월 14일
hello, I want read my excel (spreadsheet)to import data and display this data in my uitable of my GUI. I ,write the code following and it doesn't work:
% --- Executes when entered data in editable cell(s) in uitable2.
function uitable2_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable2 (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'},'FluidesAnnulaires');
filename = strcat(path,file);
set(handles.upload);
data = xlsread(filename);
set(handles.uitable2,'Data',data)
  댓글 수: 1
brigitte duran
brigitte duran 2016년 4월 14일
set(handles.upload) is a problem and set(handles.uitable2,'Data', data) as well. Thanks for your help.

댓글을 달려면 로그인하십시오.

답변 (1개)

Orion
Orion 2016년 4월 14일
Hi,
For what I see your callback is not at a proper place.
The CellEditCallback is called when you modify manually the content of a uitable.
For now, I guess you should let this callback empty and create a pushbutton to get and load your data and insert it in the uitable.
something like
function uitable2_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% 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)
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[file,path] = uigetfile({'*.xls;*.xlsx','Excel Files'},'FluidesAnnulaires');
filename = fullfile(path,file);
data = xlsread(filename);
set(handles.uitable2,'Data',data)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by