how to xlswrite to the same worksheet without errors?

2 次查看(过去 30 天)
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:
  1. I tried this code also with some other suggested solutions and versions of xlswrite to no avail.
  2. It ran perfectly on my friend's computer.
  3. 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!

采纳的回答

Image Analyst
Image Analyst 2014-9-7
编辑:Image Analyst 2014-9-7
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 个)

Community Treasure Hunt

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

Start Hunting!

Translated by