MATLAB: Open an excel sheet after clicking a pushbutton in GUI

excelgui

I would like to create a GUI so whenever I click the push-button (I called it OK), matlab creates an excel sheet based on an already prepared excel template. Thank you for your help.
% --- Executes on button press in OK_.
function OK__Callback(hObject, eventdata, handles)
% hObject handle to OK_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

Best Answer

Hello Michel,
Consider you have GUI " Test.m" and " Test.fig" files, along with your template " ABC.xlsx" file.
Keep all files in current directory of matlab. Now, for your GUI, there is pushbutton called ' OK'.
Consider, the template Excel file have three column ' Sr_No', ' Name', ' Age', which you want to update when you click on ' OK' push button.
so you need to update the following code into callback of pushbutton ' OK':
% --- Executes on button press in OK_.
function OK__Callback(hObject, eventdata, handles)
% hObject handle to OK_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Sr_No = {'1';'2';'3';'4';'5'};
Name = {'A';'B';'C';'D';'E'};
Age = {'10';'11';'12';'13';'15'};
final_Data = [Sr_No,Name,Age];
xlswrite('ABC.xlsx',final_Data,'Sheet1','A2');
winopen('ABC.xlsx');
Related Question