problem with xlswrite windows

조회 수: 2 (최근 30일)
abdiel pantoja meneses
abdiel pantoja meneses 2020년 5월 7일
편집: abdiel pantoja meneses 2020년 5월 7일
I have the following code in windows
Dat=[1 2 3]
direccion=uigetdir;
aux=[direccion,'Mediciones','_','%s.xlsx'];
Name=sprintf(aux,datestr(now));
xlswrite(Name,Dat,'Data','A1')
error using xlswrite

채택된 답변

Akihumi
Akihumi 2020년 5월 7일
편집: Akihumi 2020년 5월 7일
I think the filename doesn't allow ':' if you use datestr(now)
Try using
sprintf('%02.0f',clock)
Besides, I would suggest using the following syntex for the filename:
Name=sprintf('%s%sMediciones_%s.xlsx', direccion, filesep, sprintf('%02.0f',clock));
  댓글 수: 1
abdiel pantoja meneses
abdiel pantoja meneses 2020년 5월 7일
편집: abdiel pantoja meneses 2020년 5월 7일
Thank you
In this way I was able to achieve what I wanted to save the excel file and that its name was with the current date and time

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Quad
Quad 2020년 5월 7일
There are a few things that could cause this to go wrong.
1) Be sure that the name you are providing is a valid name for excel. I believe datestr(now) produces a string which has special characters that are not acceptable for the name of an excel file.
2) Make sure to test out uigetdir before using it. On a windows machine, uigetdir does not return a '\' at the end of the directory.
3) This one is a little tricky! I don't think it's actually your xlswrite that is the problem, I think it is your sprintf statement. Notice that the backslash character is a special character, and you need to use a double backslash for matlab to ignore it as a special character. Any time sprintf is called, it will treat a single backslash as a special character, and will reduce any double backslash to a single backslash. For example, you could try something like this:
Dat=[1 2 3]
direccion=uigetdir;
split = strsplit(direccion,'\');
direccion = sprintf('%s\\\\',split{:});
aux=[direccion,'Mediciones','_','%s.xlsx'];
Name=sprintf(aux,'1');
xlswrite(Name,Dat,'Data','A1')
I recommend you display the output from split, direccion, aux, and Name in order to see what is happening in the provided code. Notice I replaced datestr(now) with '1' because of the special characters in datestr

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by