how to xlswrite to the same worksheet without errors?
2 views (last 30 days)
Show older comments
I have received an .exe file, compiled in MATLAB, which repeatedly uses xlswrite to paste figures and 2D arrays into the same excel worksheet. The problem is that eventually (after a random amount of runs) I get the error: "The file is not writable. It may be locked by another process. MATLAB:xlswrite:LockedFile". I tried this test code to examine what the problem is:
r = 50; s = 1; i = 0;
while s == 1
i = i + 1;
[s,~] = xlswrite('TEST.xls',rand(r),1,['A' num2str(r*(i-1)+1)]);
[i s]
%pause(3);
end
A few comments:
- I tried this code also with some other suggested solutions and versions of xlswrite to no avail.
- It ran perfectly on my friend's computer.
- Pausing for 3secs also does the job (no less than 3), but this is not a solution.
Does anyone know how to solve this? Is it connected to a specific wait-time before each run finishes? Thanks a lot!
0 Comments
Accepted Answer
Image Analyst
on 7 Sep 2014
Edited: Image Analyst
on 7 Sep 2014
You'd be best off using ActiveX rather than xlswrite repeatedly if there are more than about 3 writes. I've attached a demo. Other than that, it might be a timing issue. The pause(3) seems a bit long but if it works, then go for it (if you don't want to learn ActiveX).
0 Comments
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!