Generating multiple excel files

2 visualizaciones (últimos 30 días)
Ahmad Fakih
Ahmad Fakih el 10 de Nov. de 2019
Respondida: Image Analyst el 10 de Nov. de 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?

Respuesta aceptada

Image Analyst
Image Analyst el 10 de Nov. de 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)
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);
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.

Más respuestas (1)

Oren B
Oren B el 10 de Nov. de 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')


Community Treasure Hunt

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

Start Hunting!

Translated by