How do I use writetable to output a filename depending on my input?
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
For example,
data = input('Input your excel file: ','s');
So, if I am to put my input of '15th of June', I want to get an output of
Table; % assuming I've coded some things based on data and my final product is Table
writetable(Table,'Schedule for 15th of June.xlsx');
But the data input may change and I want the default to be 'Schedule for "data".xlsx'. I can't figure how to do it. I've noticed that the file name has to be purely text.
I've also looked at the possibility of naming the 'Table' as the table;
Schedule_for_15th_of_June;
writetable(Schedule_for_15th_of_June);
But I know that that will only output a file in .txt, while my desired file type is .xlsx. I want to change writetable to make it so the default output is .xlsx but I don't know how to and I'm afraid it'll break the function. I appreciate any of your help in advance.
댓글 수: 0
채택된 답변
  Aakash
      
 2023년 6월 15일
        Create filename before passing it to writetable using sprintf as below:
filename = sprintf('Schedule for %s.xlsx', data);
writetable(table, filename, 'FileType', 'spreadsheet');
Hope this helps you!!
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

