Generating multiple excel files
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ahmad Fakih
le 10 Nov 2019
Réponse apportée : Image Analyst
le 10 Nov 2019
Dear members,
I have an excel file named Template.xls. I need to generate n number of excel files having the same content as Template.xls but named: Template1, Template2... Templaten.
How can I do this in MATLAB?
0 commentaires
Réponse acceptée
Image Analyst
le 10 Nov 2019
Use copyfile() to make copies of a file:
inputFolder = pwd; % or wherever
sourceFile = fullfile(inputFolder, 'template.xlsx')
if ~isfile(sourceFile) % First check to see that the source file exists.
errorMessage = sprintf('Error: source file not found:\n%s', sourceFile)
uiwait(warndlg(errorMessage));
return;
end
outputFolder = pwd; % or wherever
% Now make n copies, with different names, in the output folder.
for k = 1 : n
baseFileName = sprintf('Template%d.xlsx', k)
outputFile = fullfile(outputFolder,baseFileName)
copyfile(sourceFile, outputFile);
end
Use %3.3d if you want leading zeros, like Template007 instead of Template7. This can make it nicer to see sorted files in your OS.
0 commentaires
Plus de réponses (1)
Oren B
le 10 Nov 2019
load patients
data = table(Gender,Smoker,Height,Weight);
number_exsel_file = 3
for n = 1:number_exsel_file
writetable(data, ['Template',num2str(n),'.xls'], 'sheet', 1, 'Range', 'A1')
end
0 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!