Generating multiple excel files

3 ビュー (過去 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 Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by