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

4 ビュー (過去 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 Center および File ExchangeData Import from MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by