MATLAB Answers

How to change the filename in xlswrite using loop

조회 수: 13(최근 30일)
Hello everyone,
now I am writing the one .xlsx file with 19 sheets. For which my code is working properly. This is what I am written till now
for a=1:length(sheets)
xlswrite('rough.xlsx',final{a},sheet{a},xlrange1);
end
Now what actually I want is that I need to write my answers in for different xlsx sheets. Means for every one input sheet I will get one xlsx file with 19 sheets. So, how can I change the filename with a different for loop so that for every different input sheet i will get different xlsx file with 19 sheets each.
means as I am able to change the sheets number but how to change the filename.
Thanks in advance

  댓글 수: 0

로그인 to comment.

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 19 Dec 2019
편집: KALYAN ACHARJYA 19 Dec 2019
for i=1:
xlswrite([strcat('Any_Initial_name',num2str(j)),'.xlsx'],file_to_write,'Sheet');
end

  댓글 수: 1

로그인 to comment.

추가 답변(1개)

Ankit
Ankit 19 Dec 2019
using xlswrite in a loop will effect performance. Try this FEX: https://de.mathworks.com/matlabcentral/fileexchange/10465-xlswrite1.
You can try the below changes
for a=1:length(sheets)
fileName = ['rough_', int2str(a), '.xlsx'];
xlswrite(fileName,ARRAY,SHEET,RANGE);
end

  댓글 수: 3

Prakhar Modi
Prakhar Modi 20 Dec 2019
I tried what you have suggested but still I am not getting three different excel sheets as an output. only one sheet is appearing in output with a single filename
Ankit
Ankit 20 Dec 2019
I tried with random values it is working for me. If I am not wrong length(sheets) = 3?
Just change length(sheets) =3 and let me know your results.
Prakhar Modi
Prakhar Modi 20 Dec 2019
Thanks man.
But I tried with kalyan answer and that worked for me.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그

제품


릴리스

R2018a

Translated by