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!