Read or write in the .xlsx files

8 visualizaciones (últimos 30 días)
Itachi
Itachi el 19 de Ag. de 2012
Comentada: Image Analyst el 1 de Mayo de 2015
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 comentarios
José-Luis
José-Luis el 19 de Ag. de 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.
Itachi
Itachi el 19 de Ag. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

José-Luis
José-Luis el 19 de Ag. de 2012
I'll make it an answer.
I think you can, see the link:
Cheers!
  2 comentarios
Itachi
Itachi el 19 de Ag. de 2012
Thank you, that's exactly what I've been looking for.
Suraj Srivastava
Suraj Srivastava el 30 de Abr. de 2015
Hi,
Colud you please tell me that, How can I use xlswrite1 in GUI. I have used it, but it gives error.
Any comment is appreciated.
Thanks, Suraj

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 19 de Ag. de 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.

Suraj Srivastava
Suraj Srivastava el 30 de Abr. de 2015
Hi,
Colud you please tell me that, How can I use xlswrite1 in GUI. I have used it, but it gives error.
Any comment is appreciated.
Thanks, Suraj
  3 comentarios
Suraj Srivastava
Suraj Srivastava el 1 de Mayo de 2015
Hi, Thanks for your valuable reply. The thing is that I am using xlsread and xlswrite functions so many times in my GUI code. And I am using it in one of my optimization process. The code runs smoothly but taking very long time. Also if I give 3000 iterations to run then for all the 3000 simulations it runs well but at the end it gives error. But if run the same for 50 iterations it did'nt gives any error. I tried using xlswrite11 function, it runs for normal coding but in GUI it gives error. Kindly suggest me what I should to improve the speed of my code or to rectify the error or how to use xlswrite1 function(As it is not clear to me from ExcelDemo.m)
Kindly help me out.
Thanks, Suraj
Image Analyst
Image Analyst el 1 de Mayo de 2015
Of course it takes a long time. You're launching Excel 3000 times and shutting down Excel 3000 times. It's going to take like a trillion billion years to do that - maybe longer! That's why I gave you an Active X solution that uses xlswrite1() that will do this in just a few seconds. I encourage you to learn it. It's not that hard. If a big dummy like me could figure it out, I'm sure a brilliant engineer like you can too. If you don't like my well commented tutorial, then you can check out the Mathworks ActiveX tutorials instead. xlswrite1() assumes you've used ActiveX to create an Excel object in advance - you can do this with just one line of code, though it would be better to make it more robust and use a few lines of code to handle situation like Excel is already running, it already has your workbook open, etc.

Iniciar sesión para comentar.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by