Clear Filters
Clear Filters

Sudden error when exporting with 'writecell' in MATLAB

16 views (last 30 days)
I had a program with the following lines that worked fine for a few weeks:
Cell= {some cell array}
Matrix= [some Matrix]
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?

Answers (2)

DUY Nguyen
DUY Nguyen on 2 Mar 2023
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');

Nithin Kumar
Nithin Kumar on 2 Mar 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 Comment
CreCre on 2 Mar 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!

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!