Using xlswrite with Excel 2013

2 views (last 30 days)
susato
susato on 7 Aug 2013
Edited: Beneyaz Begum on 19 Jan 2022
I have a new Windows 8 laptop running MS Office 2013 and MATLAB R2013a.
The xlswrite function does not seem to work with this version of Excel®. A program developed at my school's computer lab using academic site-license MATLAB R2013 and MS Office 2010 under Win 7 worked fine in the development environment but shows fatal errors on this laptop when trying to write to an Excel 2013 spreadsheet. The program reads the names (strings) of purchasers and items, and weights (floating point numbers) of items out of an excel worksheet using xlsread, processes the data, and outputs processed data to an empty area of the worksheet. Our Excel files are in .xlsx format, not .xls.
The program fails with this error message:
Error using xlswrite (line 220)
Error registering event(s), Advise failed
Error in myprogram (line 164)
xlswrite(file, wt(n), worksheet, [alph({person{1} (3))} num2str(n)]);|
We are sure that the problem does not lie with the file and worksheet name nor the variable types, brackets or indices because the routine works perfectly under Win 7 and Excel 2010.
Besides outputting to a text file, is there any way to fix this?

Accepted Answer

Mihir Pai
Mihir Pai on 27 Jun 2014
Hey susato! I'm sorry if this comes a year too late but I thought I might as well share my experience with this in case anyone else stumbles across this error.
I got this error on the n-th iteration of my tremendously huge for loop which caused it to break out of the loop and terminate the program. What seemed to be happening with my case is that each successive loop of the code accessed the MATLAB's Excel drivers in a read/write execution and started filling up the RAM with instructions to the point where the read/write executions failed as you mentioned.
What solved it was adding a pause() for about 5 seconds before the next iteration of the loop. What also helped was not having too many open xls/xlsx spreadsheets at the time since this too fills up your RAM (I ran numerous stress tests to confirm this, and yes the added 5 seconds lengthened my run time considerably).
In summary: leave MATLAB alone to do its thing since the handshake with Excel is pretty aggressive in memory consumption.
Hope this helps!
- Mihir
PS: I run MATLAB R2012b/R2014a on an i7 - 2.1 GHz with 8 GB RAM on Windows 8/8 Pro, Microsoft Office 2010/2013
  2 Comments
susato
susato on 28 Jun 2014
Hi Mihir - this is exactly the right approach - a student intern here arrived at it independently. We started with a 1 second delay at each xlswrite command and gradually brought it down to a 1 ms. delay. (0.1 ms proved too small on this particular machine and spreadsheet) Apparently xlswrite opens and closes Excel (or maybe only the file) each time a write is performed. And as you point out , opening and closing MS office documents can be a long process even on a workstation like ours: a 2.4 GHz quad core i7 notebook with 8 Gb memory.
The program does run considerably slower now, but far more importantly, it runs to the end, finishing with the correct results.
Many thanks,
susato
Beneyaz Begum
Beneyaz Begum on 19 Jan 2022
Edited: Beneyaz Begum on 19 Jan 2022
Thank you Mihir and Susato. I am also running a similar problem statement with xlswrite() using for loop for 25 different patterns. And each pattern loops for multiple number of times. When I am opening multiple matlab editor to run different expeiments, with 2 or 3 editors it turns out to be too slow for my workstation.
Today, I encountered a similar such error with my experiment. Atleast, now I could really find an answer to what is really happening at the backend. Thanks for suggesting the solution.
Regards,
Beneyaz

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!