Matlab repeated use of xlsread and xlswrite to network drive

4 ビュー (過去 30 日間)
Andrew Bazyk
Andrew Bazyk 2014 年 8 月 11 日
回答済み: Image Analyst 2014 年 8 月 11 日
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.

採用された回答

Image Analyst
Image Analyst 2014 年 8 月 11 日
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.

その他の回答 (1 件)

Joseph Cheng
Joseph Cheng 2014 年 8 月 11 日
編集済み: Joseph Cheng 2014 年 8 月 11 日
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.
  1 件のコメント
Andrew Bazyk
Andrew Bazyk 2014 年 8 月 11 日
Thanks for your suggestion. I have modified your routine and am going to give it a try with a large set of files. I'm trying it with no pause in hopes that it won't complete and then I'm going to try again with a pause. I will let you know what I find out.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by