set(handles.upload) is a problem and set(handles.uitable2,'Data', data) as well. Thanks for your help.
How can I edit my Excel data in a UItable Gui?
2 次查看(过去 30 天)
显示 更早的评论
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 个)
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!