Matlab repeated use of xlsread and xlswrite to network drive
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Andrew Bazyk
le 11 Août 2014
Réponse apportée : Image Analyst
le 11 Août 2014
I have a script that loops through raw Excel data files and writes out resulting Excel data files with nine sheets each. I call xlsread one and xlswrite nine times for each iteration of the loop. All files are being read from and written to a network drive. I am receiving an error saying that the either being read from or written to can't be found. This does not happen to one particular file, but occurs randomly.
What could be causing an exisiting file or a file being written, to not be found? Could this be due to using a network drive?
An example of an error I get would be:
XLSREAD unable to open file xxx. File xxx not found.
0 commentaires
Réponse acceptée
Image Analyst
le 11 Août 2014
It could be a timing issue. Every time you call them, it launches and shuts down Excel. Maybe it's not quite done shutting down and you come along and try to launch it again. Try putting in a half second pause right after you call xlsread() or xlswrite(). If that doesn't work, use ActiveX. Actually use ActiveX anyway it will be so much faster you won't believe it. Attached is a demo. Never call xlwrite or xlsread more than about 2 or 3 times. Since you're doing 900 pokes, it will take forever, versus a few seconds with ActiveX.
0 commentaires
Plus de réponses (1)
Joseph Cheng
le 11 Août 2014
Modifié(e) : Joseph Cheng
le 11 Août 2014
Without seeing how you're doing this i would say put in a debugging section in your script to check for key items. place a break point on catch part of a try,catch for when the file fails to be read/written to. Then you can check if the script is indeed specifying the file name and location correctly.
to see if it is a network issue perhaps a routine such as
n=0;
Nofile = 0;
while Nofile = 0 & n<100
File = dir(fullfile(folder,file))
if isempty(File)
Nofile = 1;
else
n=n+1;
pause(.1)
end
end
and see if there are any breaks in the communication. Perhaps the network admin limits the how quickly+frequently you can querying the network drive.
in either case you can use the while loop above with a few modifications. Firstly check for the file and if it exists then perform your read or write. if it comes out with a no file then pause for a while and try again for say 5 iterations. in the case that there is no file then you've got a timeout condition.
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!