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

1 回表示 (過去 30 日間)
frankenberry
frankenberry 2020 年 3 月 26 日
回答済み: frankenberry 2020 年 4 月 4 日
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 Center および File ExchangeSpreadsheets についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by