How to avoid overwrite in excel in apps designer

조회 수: 1 (최근 30일)
Mo
Mo 2023년 1월 5일
댓글: Mo 2023년 1월 5일
Hi
I read many articles about how to avoid overwrite (WriteMode, Append, etc.) when exporting data from Matlab to excel, but none of them helped me to fix my problem.
I want to export tab data (table format) to Excel by selecting the path and also adding new data in next row. When I close the app and restart export to Excel, everything overwites in the previous excel file instead of adding to the end of last row. How I can fix the code?
My code is:
%keep data in the UITable3%
tab = app.UITable3.Data;
% get directory
selectPath = uigetdir('C:\','Please select Path for saving excel file');
%create xlsx file (Data.xlsx)%
filename = ('Data.xlsx');
writecell(tab,fullfile(selectPath,filename));

채택된 답변

Kevin Holly
Kevin Holly 2023년 1월 5일
You can change the write mode as such:
writecell(tab,fullfile(selectPath,filename),'WriteMode','append');
  댓글 수: 3
Kevin Holly
Kevin Holly 2023년 1월 5일
편집: Kevin Holly 2023년 1월 5일
"WriteMode" became available starting in R2020a. Are you able to get access to a new version of MATLAB?
Alternatively, you could use xlsappend found on the File Exchange:
https://www.mathworks.com/matlabcentral/fileexchange/28600-xlsappend
Mo
Mo 2023년 1월 5일
It works in R2022b now. Many thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by