Generating multiple excel files
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
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.
댓글 수: 0
추가 답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!