Generating multiple excel files

조회 수: 1 (최근 30일)
Ahmad Fakih
Ahmad Fakih 2019년 11월 10일
답변: Image Analyst 2019년 11월 10일
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?

채택된 답변

Image Analyst
Image Analyst 2019년 11월 10일
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.

추가 답변 (1개)

Oren B
Oren B 2019년 11월 10일
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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by