output appdesigner data collected with button press to next row in excel

1 visualización (últimos 30 días)
I have code that writes out data (string) to an excel spreadsheet. When the user clicks <Submit>, the information in the text area is output to an excel file ("ArticleRequest.xlsx"). This part works well in Matlab app designer 2019b version 5. When I run the app a second time, the data should go to the next row in excel but instead it overwrites the information in the first cell. How can I fix this? I have looked everywhere on this site, on Stack Overflow, in Matlab Help and no one seems to have a code that works in app designer. The code that works is below. The last 4 rows are directions to the user after the data is output to the excel file. Any helpful suggestions are appreciated.
% Button pushed function: SubmitButton
function SubmitButtonPushed(app, event)
filename = 'ArticleRequest.xlsx'; %file
M = {app.TextArea_Email.Value}; %data
writecell(M,filename,'Sheet','EmailReq'); %write data to cell in table
app.TextArea_Email.Value = 'Press <Next> to continue.';
app.SubmitButton.Visible = 'off';
uiconfirm(app.UIFigure,{'The file has been created.','Click OK'},'File Creation Confirmation','Icon','Success');
app.NextButton_Email.Enable = 'on';
end

Respuesta aceptada

frankenberry
frankenberry el 4 de Abr. de 2020
This Works!
% Button pushed function: SubmitButton
function SubmitButtonPushed(app, event)
filename = 'ArticleRequest.xlsx'; %file
newEmail = {app.TextArea_Email.Value}; %data
Emails = readcell('ArticleRequest.xlsx','Range','Var1'); % read in emails
% append new row to emails array
Emails = [Emails; newEmail]; % append new email to list of emails
writecell(Emails,filename); % write it to file
app.TextArea_Email.Value = 'Press <Next> to continue.';
app.SubmitButton.Visible = 'off';
uiconfirm(app.UIFigure,{'The file has been created.','Click OK'},'File Creation Confirmation','Icon','Success');
app.NextButton_Email.Enable = 'on';
end

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by