How can I add a row and continue writing in the same Excell with matlab interface?

9 views (last 30 days)
I have this code and I need to update patients information to the excel but, I want to have an excel with different patients information. So, I need an excel for example like this:
Maria gutierrez 752896 24/05/2017 Fernando Ortega 587458 48/02/2017
This is my code for the excel: function Guardar_Callback(hObject, eventdata, handles) global numero
numero=0; numero=numero+1; data.nombre=get(handles.edit1,'String'); data.apellido=get(handles.edit2,'String'); data.registro=get(handles.edit3,'String'); data.fecha=get(handles.dateEditBoxHandle,'String');
fid=fopen('DATA.txt','w+'); xlswrite('D:\interfaz\dd.xls',{numero,data.nombre,data.apellido,data.registro,data.fecha},'Hoja1','A2'); xlswrite('D:\interfaz\dd.xls',{'Nº','Nombre','Apellido','Registro','Fecha'} ,'Hoja1','A1');
fclose(fid);

Answers (1)

Nagini Venkata Krishna Kumari Palem
From an initial review of your code, I understand that you already added column headers and one row of values. Now, you wish to add more rows to the same excel sheet.
You can add a new row by incrementing the 'xlrange' value i.e., A3, A4, A5 and so on. For example,
xlswrite(filename, {data1,data2,...,dataN}, 'Sheet1', 'A3');
xlswrite(filename, {data1,data2,...,dataN}, 'Sheet1', 'A4');
xlswrite(filename, {data1,data2,...,dataN}, 'Sheet1', 'A5');
If you want to automate the incremental process, you can do as follows,
xlswrite(filename, {data1,data2,...,dataN}, 'Sheet1', ['A' num2str(numero)]);
Following documentations are more helpful,

Community Treasure Hunt

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

Start Hunting!