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

조회 수: 1 (최근 30일)
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

채택된 답변

frankenberry
frankenberry 2020년 4월 4일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by