Write 10 excel for loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Now I have one original.xlsx, I want to write Data in Sheet1 from E1.
xlswrite('Original.xlsx',Data,'Sheet1','E1')
How do I write 10 different Data{#} into Original.xlsx as different excel name, all in Sheet1 from E1.
for i=1:10
xlswrite('Original.xlsx',Data{i},'Sheet1','E1')?
2 commentaires
Walter Roberson
le 4 Mar 2016
To confirm, you want to produce just one output file, right? Do you want the ten in different sheets, or do you want them to go into E1 then E2 then E3 and so on? Or do you want the first to start at E1 and then the second to be in E but below where-ever the first finished? Or ...?
Réponse acceptée
Walter Roberson
le 4 Mar 2016
filenames = {'January.xlsx', 'February.xlsx', 'Cheezburger.xlsx', 'Durango95.xlsx', 'EschewObfuscation.xlsx', ....};
for i=1:10
xlswrite(filenames{i}, Data{i}, 'Sheet1','E1');
end
3 commentaires
Walter Roberson
le 4 Mar 2016
I am not sure what you mean; perhaps you mean something like,
filenames = {'January.xlsx', 'February.xlsx', 'Cheezburger.xlsx', 'Durango95.xlsx', 'EschewObfuscation.xlsx', ....};
[~, ~, orig_raw] = xlsread('Original.xlsx', 'Sheet1');
for i=1:10
xlswrite(filenames{i}, orig_raw, 'Sheet1');
xlswrite(filenames{i}, Data{i}, 'Sheet1','E1');
end
However if you were going to do that then I would use
filenames = {'January.xlsx', 'February.xlsx', 'Cheezburger.xlsx', 'Durango95.xlsx', 'EschewObfuscation.xlsx', ....};
[~, ~, orig_raw] = xlsread('Original.xlsx', 'Sheet1');
for i=1:10
outdata = orig_raw;
new_data = Data{i};
outdata(1:length(new_data),5) = new_data;
xlswrite(filenames{i}, outdata, 'Sheet1');
end
Note: if Data{i} a numeric vector then you would use
for i=1:10
outdata = orig_raw;
new_data = num2cell(Data{i});
outdata(1:length(new_data),5) = new_data;
xlswrite(filenames{i}, outdata, 'Sheet1');
end
But if Data{i} is a numeric scalar or string then you would use
for i=1:10
outdata = orig_raw;
new_data = Data{i};
outdata{1,5} = new_data;
xlswrite(filenames{i}, outdata, 'Sheet1');
end
Plus de réponses (1)
Joachim Schlosser
le 4 Mar 2016
You can write the whole cell array at once. See the cell array example in the online help: http://www.mathworks.com/help/releases/R2015b/matlab/ref/xlswrite.html
If you are asking about the for loop because you first are calculating each cell before writing, I'd advise to export to Excel in a separate step after the loop for performance reasons.
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!