How do I incrementally increase an excel file everytime I run the code to avoid overwriting

조회 수: 2 (최근 30일)
I create my excel sheet using writetable(T,'Test no21.xlsx') I would like to incrementally increase the number of the excel file to avoid overwriting the previous documents, how can I achieve that?

채택된 답변

Geoff Hayes
Geoff Hayes 2022년 10월 3일
@Mohamed Sardheye - try using sprintf like
k = 22;
filename = sprintf('Test no%d.xlsx', k);
writetable(T, filename);
Or do you need to determine the 21 from the original file first?
  댓글 수: 3
Geoff Hayes
Geoff Hayes 2022년 10월 7일
@Mohamed Sardheye - you could use regexpi to match on the integers in your filename. Perhaps something like
filename = 'Test no21.xlsx';
newFileNumber = str2double(filename(regexpi(filename, '[0-9]'))) + 1;
newFilename = sprintf('Test no%d.xlsx', newFileNumber);

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

추가 답변 (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