How can I avoid generating extra sheets in a loop while using "writetable" function?
조회 수: 5 (최근 30일)
이전 댓글 표시
Abolfazl Jalali Shahrood
2018년 6월 18일
댓글: Abolfazl Jalali Shahrood
2018년 6월 22일
Here is the code:
---------------------------
Year=[1993 2003 2011 2015]
for an=1:4
Inputfile= xlsread(Inputfile,num2str(Year(an)));
x=Inputfile(:,1);y=Inputfile(:,2);
T=table(x,y);
filename2=strcat(num3,RIVNOM,'poly','.xls');
sheet=num2str(Year(an));
writetable(T,filename2,'sheet',sheet);
end
-----------------------------------
It results in an excel file which has three extra sheets at the beginning (sheet1, sheet2, sheet3) and then (1993,2003,2011,2015).
Here is the question: how to avoid generating extra and empty sheets.
Thank you.
댓글 수: 0
채택된 답변
Tristan Yang
2018년 6월 21일
Hi Abolfazl,
Unfortunately there is no easy way to use "writetable" function itself to change this behavior. You may consider the following:
1. You can first use the writetable 'sheet' option with index instead of the sheet names, which would write your data in 'sheet1', 'sheet2', 'sheet3' and 'sheet4'. Then use the solution from this post to change the name into the years using actxserver.
2. You can also keep your current workflow and try to remove the extra sheets by using the solution from this post with actxserver.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!