Read or write in the .xlsx files

Asked by MS AR on 19 Aug 2012
Latest activity Commented on by MS AR on 19 Aug 2012

Hi guys, I've written a code with alot of loops and in each loop there the xlsread or xlswrite commands. I've installed Excel 2010 and I'm not using it when I'm running the code . These are the errors:

It may be locked by another process.

or

Error registering event(s), Advise failed
Error in registerevent>addevent (line 148)
list(m+1) = handle.listener(h, eventname, {@comeventcallback, eventhandler});
Error in registerevent (line 94)
        addevent(h, event, eventhandler);
Error in xlsreadCOM (line 11)
    Excel.registerevent({'WorkbookActivate', @WorkbookActivateHandler});
Error in xlsread (line 230)
        [numericData, textData, rawData, customOutput] = xlsreadCOM(file, sheet, range,
        Excel, customFun);

Please help me out. thanks in advance.

4 Comments

MS AR on 19 Aug 2012

It's happening because I'm using too much xlsread or xlswrite functions in the code, But why is that?! Thanks

José-Luis on 19 Aug 2012

Every time you launch xlswrite/read, excel is launched, processes your commands and closes. That is heavy business. It is hard to guess what might cause your problem without knowing the structure of your code, what kind of data you have, etc... So for others to help, more information is needed. A recommendation on my part would be to look at memory comsumption when your process is running, if it spikes then maybe you have too many calls to that function, but that's just a wild guess.

MS AR on 19 Aug 2012

Dear Guerrero, Your guess is correct. I use the xlsread/write to read/write vectors from/into the Excel file too many times. Is there no way to tell MATLAB to open the file and close it whenever the code is finished?

MS AR

Products

2 Answers

Answer by José-Luis on 19 Aug 2012
Accepted answer

I'll make it an answer.

I think you can, see the link:

http://www.mathworks.se/matlabcentral/answers/46161#comment_95151

Cheers!

1 Comment

MS AR on 19 Aug 2012

Thank you, that's exactly what I've been looking for.

José-Luis
Answer by Image Analyst on 19 Aug 2012

My guess is that you already have Excel open with that workbook. If something strange happened, like you used ActiveX and hid Excel but never closed it, then Excel may still be running even if you can't see it in the task bar. In that case, if you're using Windows, type control-shift-Esc to bring up the process list, and kill Excel.

0 Comments

Image Analyst

Contact us