I keep getting the error, "Unable to write to file 'xxxx.xlsx'. You may not have write permissions or the file may be open by another application."
Mostra commenti meno recenti
I keep receiving this error when attempting to write tables to Excel from MATLAB.
%% Velocity Tables
T1 = table(vx1,'VariableNames',{'CummulativeVelocity'});
T2 = table(vy1,'VariableNames',{'CummulativeVelocity'});
T3 = table(vz1,'VariableNames',{'CummulativeVelocity'});
T4 = table(vx2,'VariableNames',{'CummulativeVelocity'});
T5 = table(vy2,'VariableNames',{'CummulativeVelocity'});
T6 = table(vz2,'VariableNames',{'CummulativeVelocity'});
T7 = table(vx3,'VariableNames',{'CummulativeVelocity'});
T8 = table(vy3,'VariableNames',{'CummulativeVelocity'});
T9 = table(vz3,'VariableNames',{'CummulativeVelocity'});
T10 = table(vx4,'VariableNames',{'CummulativeVelocity'});
T11 = table(vy4,'VariableNames',{'CummulativeVelocity'});
T12 = table(vz4,'VariableNames',{'CummulativeVelocity'});
filename = 'Velocity2.xlsx';
writetable(T1,filename,'Sheet',1,'Range','A1');
writetable(T2,filename,'Sheet',1,'Range','C1');
writetable(T3,filename,'Sheet',1,'Range','E1');
writetable(T4,filename,'Sheet',2,'Range','A1');
writetable(T5,filename,'Sheet',2,'Range','C1');
writetable(T6,filename,'Sheet',2,'Range','E1');
writetable(T7,filename,'Sheet',3,'Range','A1');
writetable(T8,filename,'Sheet',3,'Range','C1');
writetable(T9,filename,'Sheet',3,'Range','E1');
writetable(T10,filename,'Sheet',4,'Range','A1');
writetable(T11,filename,'Sheet',4,'Range','C1');
writetable(T12,filename,'Sheet',4,'Range','E1');
Here is the code I am using. The code works fine for the first instance of writetable, but the error will come up when attempting to run any other instance. I have found that I can manually end the Excel process in Task Manager, but this has to be done every time, while also creating a second copy of the worksheet. This second worksheet is the one that has the new table written in it. So, in order to continue the process I have to rename the copy and delete the previous version.
There must be a way to either better write this code (I am still pretty green), or to add something to fix this error. I don't kow what either of these solutions would be. Also, Excel is closed for each run of writetable.
2 Commenti
John Doe
il 7 Ott 2019
A few things...
- Don't dynamically name variables in workspace
- You don't want to be calling writetable repeatedly, it should all be done in one operation.
- Where ever you have multiple repeated lines like that, there is an easier way
Can you show the code you used to create vx1, vy1 vz1 etc. Lets get that in to better format then deal with creating the xlsx.
Jesse Finnell
il 7 Ott 2019
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Spreadsheets in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!