How do I use writetable to output a filename depending on my input?
5 views (last 30 days)
Show older comments
Stanley Martin Siagian
on 15 Jun 2023
Commented: Stanley Martin Siagian
on 15 Jun 2023
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 Comments
Accepted Answer
Aakash
on 15 Jun 2023
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!!
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!