Sudden error when exporting with 'writecell' in MATLAB

23 visualizaciones (últimos 30 días)
CreCre
CreCre el 27 de Feb. de 2023
Comentada: CreCre el 2 de Mzo. de 2023
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?

Respuestas (2)

DUY Nguyen
DUY Nguyen el 2 de Mzo. de 2023
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 comentario
CreCre
CreCre el 2 de Mzo. de 2023
Unfortunately that gives me the same error message but thank you!

Iniciar sesión para comentar.


Nithin Kumar
Nithin Kumar el 2 de Mzo. de 2023
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 comentario
CreCre
CreCre el 2 de Mzo. de 2023
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!

Iniciar sesión para comentar.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by