Write 10 excel for loop
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2016-3-4
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 ...?
采纳的回答
Walter Roberson
2016-3-4
filenames = {'January.xlsx', 'February.xlsx', 'Cheezburger.xlsx', 'Durango95.xlsx', 'EschewObfuscation.xlsx', ....};
for i=1:10
xlswrite(filenames{i}, Data{i}, 'Sheet1','E1');
end
3 个评论
Walter Roberson
2016-3-4
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
更多回答(1 个)
Joachim Schlosser
2016-3-4
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!