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:
- 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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!