Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matlab to Excel issue
Date: Tue, 25 Sep 2007 21:12:45 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 100
Message-ID: <fdbtkd$i5c$1@fred.mathworks.com>
References: <fd9i2n$adu$1@fred.mathworks.com> <fd9m41$68t$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1190754765 18604 172.30.248.37 (25 Sep 2007 21:12:45 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 25 Sep 2007 21:12:45 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1070623
Xref: news.mathworks.com comp.soft-sys.matlab:430172



"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message 
<fd9m41$68t$1@fred.mathworks.com>...
> > The issue is this.  When I run my code, the program 
takes a 
> > while to process everything.  And usually the matrices 
that 
> > I work with in MatLab are on the order of [384x7] in 
size.  
> > I feel that this is an Excel memory-related issue.  
> 
> xlswrite is very inefficient, in that it does not reuse
> existing open XLS server COM connections - it reopens a 
new
> connection with each invocation. This takes a lot of time
> and system memory, especially if you run the command in a
> loop. I suggest you use xlswrite1 or officedoc, both on 
the
> File Exchange, which reuse open connections. There are a 
few
> other alternatives on the FEX - search around.
> 
> > Everytime I run my program and it stops due to the 
above 
> > error, I check the task manager and there are several 
(>30) 
> > instances of EXCEL.EXE*32's running each taking up 
~20,000K 
> > of space in Mem Usage.
> > 
> > Does anybody know what is causing this?  And if so, how 
to 
> > remedy it?
> 
> xlswrite crashed without bothering to close the open COM
> connections... You have no access to these connections and
> must delete them via the Task Manager.
> 
> > One thing that I tried to do was use the following:
> > 
> > Excel = activexsrv('Excel.Application') to start up an 
> > activexsrv for Excel, and use Excel.Quit at the end of 
the 
> > code so that I do not have recurring instances of Excel 
> > open in the Task Manager.  Is this the correct way to 
go 
> > about it?
> 
> Yes. You can edit/type xlswrite or xlswrite1 to get 
started,
> or simply use one of the aforementioned FEX submissions.
> 
> Yair Altman
> http://ymasoftware.com
> 

Thanks Yair.  I have found the xlswrite1 on the FEX and 
have attempted to use it via the insructions.  However, I 
am receiving the following error:

------------------------------------------------------------
??? Error using ==> xlswrite1
No appropriate method or public field sheets for class 
handle.

Error in ==> m_file_name at 103
xlswrite1('file_name',1,'sheet_name',range);
------------------------------------------------------------

Does this mean that I am invoking the xlswrite1 function 
wrong?

As it is now, at the beginning of my mfile I include (word 
for word):
------------------------------------------------------------
Excel = actxserver ('Excel.Application');
File='C:\M_files\M_file';

if ~exist(File,'file')
   ExcelWorkbook = Excel.workbooks.Add;
   ExcelWorkbook.SaveAs(File,1);
   ExcelWorkbook.Close(false);
end

invoke(Excel.Workbooks,'Open',File);
------------------------------------------------------------

And at the end, word for word:
------------------------------------------------------------
invoke(Excel.ActiveWorkbook,'Save');
Excel.Quit
Excel.delete
clear Excel
------------------------------------------------------------

In addition, where do I store the M-file xlswrite1?  Do I 
copy the syntax and append it at the end of my code (which 
I tried but it doesnt seem to work), or do I save it in the 
same folder as the M-file that I'm writing?

Thanks.