|
"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.
|