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

1 回表示 (過去 30 日間)
John Doe
John Doe 2020 年 12 月 2 日
コメント済み: John Doe 2020 年 12 月 2 日
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 Center および File ExchangeDevelop 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