필터 지우기
필터 지우기

Sudden error when exporting with 'writecell' in MATLAB

조회 수: 14 (최근 30일)
CreCre
CreCre 2023년 2월 27일
댓글: CreCre 2023년 3월 2일
Hi,
I had a program with the following lines that worked fine for a few weeks:
Cell= {some cell array}
Matrix= [some Matrix]
writecell(Cell,fullfile('Savedfiles','Data.xlsx'),'Sheet',2,'writemode','append')
writematrix(Matrix,fullfile('Savedfiles','Data.xlsx'),'Sheet',2,'writemode','append')
But suddendly it keeps returning the error message:
Error using writecell (line 165)
Unable to write to file 'Savedfiles\Data.xlsx'. You may not have write permissions or the file may be open by
another application.
I changed nothing except a value in the excel itself (which I have done numerous times before). Next time opening MATLAB it stopped working.
I tried:
  • using the Data it last worked with
  • checked whether the cell array and matrix are still as they should be
  • removing the lines from the context of the original script and running them
  • write those lines in another script with other values to test
  • export to another file
  • export to another location
  • checked the file permissions (all fine)
  • deleted everything and reopened in matlab
  • removed and re-added all paths
  • rebooting and restarting everything
  • removing MatlabDrive
  • exporting it to Sheet 1 rather than Sheet 2
  • Exporting it to a specific range instead of the append WriteMode
Even just exporting a single number into a 'Test.xlsx' file on my Desktop returns this error now.
I am getting a bit desperate...any advice?

답변 (2개)

DUY Nguyen
DUY Nguyen 2023년 3월 2일
Hi,
Maybe you should try another Matlab function such as xlswrite to see what happens
cell = {'Data1', 'Data2', 'Data3'; 1, 2, 3; 4, 5, 6};
xlswrite('MyFile.xlsx', cell, 'Sheet1');
  댓글 수: 1
CreCre
CreCre 2023년 3월 2일
Unfortunately that gives me the same error message but thank you!

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


Nithin Kumar
Nithin Kumar 2023년 3월 2일
Hi CreCre,
I understand that you are trying to export a cell array to an Excel file using "writecell" and have experienced a sudden error as
"Error using writecell, Unable to write to file ‘Savedfiles\Data.xlsx’ and you may not have write permissions or the file may be open by another application".
The "Unable to write to file" error message can occur in MATLAB when you try to write data to a file that is write-protected or being used by another application.
The following steps could help you solve the issue.
  • Make sure that the file you are trying to modify is not write-protected. You can check this by right-clicking on the file and selecting "properties", and then making sure that the "Read-only" checkbox is not checked.
  • Ensure that the file is not currently open in Excel or any other application. If the file is currently open, then close it before trying to write to it from MATLAB.
I hope these suggestions help you resolve the issue you are encountering.
  댓글 수: 1
CreCre
CreCre 2023년 3월 2일
Yes I already tried these steps along with the others I mentioned... It is not open anywhere either, not even Matlab drive etc. Tried it on a different device where it also definitely isnt open hidden in the background. Same error. But thank you!

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

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by