How to: write .xls into a dynamic folder name ?

1 次查看(过去 30 天)
Hello everyone,
It may be a silly question for you all folks, but i'm kick in a teeth on that one...
First the code and then what i want to do.
Prompt={'Nom', 'Surname', 'Birth_date (mm dd aaaa)','Evaluation_date (mm dd aaaa)'};
Dlgtitle=' patient data';
Def={'Duarte','Mickaels','01 01 2000','16 02 2018'};
Answer=inputdlg(Prompt,Dlgtitle,1,Def);
Patient_info={Answer{1},Answer{2},Answer{3}};
Eval_date={'Evaluation',Answer{4}};
Muscle={'Fl_Pr','Ex_Su','Bic','Tri'};
Task=[1;2;3;4;5;6];
Task1={'Task'};
mkdir ([Answer{1},' ',Answer{2},' ',num2str(Answer{3})]) % create folder with data from the prompt Patient_info
xlswrite(???????????????.xls,Task,'Fpic','A5'));
xlswrite((???????????????..xls,Patient_info,'Fpic','A2'));
xlswrite((???????????????.,Eval_date,'Fpic','A3'));
xlswrite((???????????????.,Muscle,'Fpic','B4'));
xlswrite((???????????????.,Task1,'Fpic','A4'));
I'm trying to write an .xls into the folder i just created for each of my patients from the data i put in the prompt.
If someone can help...
Thanks you all !

采纳的回答

Walter Roberson
Walter Roberson 2020-12-2
编辑:Walter Roberson 2020-12-2
folder = [Answer{1},' ',Answer{2},' ',num2str(Answer{3})];
if ~exist(folder, 'dir'); mkdir(folder); end
filename = 'patient_data.xlsx';
fullname = fullfile(folder, filename);
xlwrite(fullname, Task, 'Fpic', 'A5');
xlswrite(fullname, Patient_info, 'Fpic', 'A2');
and so on.
Are you sure you want spaces in the folder name? That is legal, but it does tend to make programming more difficult. For example,
system(['dir ', fullname])
would fail because of the spaces in the file name, and you would need
system(['dir "', fullname, '"'])
  1 个评论
John Doe
John Doe 2020-12-2
Thanks Walter, mixed with the answer of Jegan, it works flawlessly ! You're life saver !
About the folder name it's not an obligation, i have let the space because it's a small programm but i see your point :) thanks for the extra info ;)

请先登录,再进行评论。

更多回答(1 个)

Ananthi Jegan
Ananthi Jegan 2020-12-2
Hi John
You can create the excel files dynamically from the inputs received in Prompt as follows:
xlswrite(fullfile(XLFilePath,XLFilename),Array,Sheet,Range) where XLFilename should be the name of file including the extension '.xlsx' or '.xls'
An example to use from above lines of code:
xlswrite(fullfile(XLFilePath,XLFilename),Muscle,'Fpic','B4')
I hope this answers your query.
  1 个评论
John Doe
John Doe 2020-12-2
Thanks Jegan, mixed with the answer of Walter, it works flawlessly ! You're life saver too :) !

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by