Board index » delphi » TOleContainer and Excel

TOleContainer and Excel


2003-10-22 11:33:03 PM
delphi105
Hi, I am using TOleContainer to embed an Excel spreadsheet. I simply use
"CreateObjectFromFile" and "DoVerb(ovShow)" methods. The problem is when I
try to run MS-Excel to edit another spreadsheet when my app is running
displaying the spreadsheet in the OleContainer, I simply can't. The Excel
starts but won't open the spreadsheet. Another problem is that if I click in
one cell before the spreadsheet is fully loaded inside the OleContainer, I
get an "OLE Error" message. Does anybody know what's going on? I need some
general guidelines on how to use Excel inside TOleContainer.
Thank you very much!
Fabio Santos
 
 

Re:TOleContainer and Excel

I forgot to mention that I am using Delphi 6, Win XP pro and Office XP.
"Fabio Santos" <XXXX@XXXXX.COM>writes
Quote
Hi, I am using TOleContainer to embed an Excel spreadsheet. I simply
use
"CreateObjectFromFile" and "DoVerb(ovShow)" methods. The problem is when I
try to run MS-Excel to edit another spreadsheet when my app is running
displaying the spreadsheet in the OleContainer, I simply can't. The Excel
starts but won't open the spreadsheet. Another problem is that if I click
in
one cell before the spreadsheet is fully loaded inside the OleContainer, I
get an "OLE Error" message. Does anybody know what's going on? I need some
general guidelines on how to use Excel inside TOleContainer.

Thank you very much!

Fabio Santos


 

Re:TOleContainer and Excel

<<Fabio Santos:
The problem is when I try to run MS-Excel to edit another
spreadsheet when my app is running displaying the
spreadsheet in the OleContainer, I simply can't.
Quote
>
Yes. There is a problem with using the TOleContainer if
other instances of Excel will be used. The best solution is
to use the OnDeactivate and OnActivate events of your
application to call Olecontainer.Close and
OleContainer.DoVerb (or Run) respectively. (NB it must be
the events of the application, not of the form - you can
use the TApplicationEvents component for this.) That way
when the user switched to Excel, the olecontainer would
close its instance of Excel - without losing its own
contents - and allow the other instance to function
normally.
One possible drawback is that OleContainer.Close saves the
workbook, but if you need to use TOleContainers and Excel
together I think you will have to live with that.
--
Deborah Pate (TeamB) delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html
 

Re:TOleContainer and Excel

I will try that. Thank you very much!
"Deborah Pate (TeamB)" <XXXX@XXXXX.COM>wrote in
message news:XXXX@XXXXX.COM...
Quote
<<Fabio Santos:
The problem is when I try to run MS-Excel to edit another
spreadsheet when my app is running displaying the
spreadsheet in the OleContainer, I simply can't.
>>

Yes. There is a problem with using the TOleContainer if
other instances of Excel will be used. The best solution is
to use the OnDeactivate and OnActivate events of your
application to call Olecontainer.Close and
OleContainer.DoVerb (or Run) respectively. (NB it must be
the events of the application, not of the form - you can
use the TApplicationEvents component for this.) That way
when the user switched to Excel, the olecontainer would
close its instance of Excel - without losing its own
contents - and allow the other instance to function
normally.

One possible drawback is that OleContainer.Close saves the
workbook, but if you need to use TOleContainers and Excel
together I think you will have to live with that.

--
Deborah Pate (TeamB) delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html


 

Re:TOleContainer and Excel

One more thing so, there is no way of using Excel while a spreadsheet is
open in an OleContainer, right? that is what I wanted to be able to do.
Thanks.
"Deborah Pate (TeamB)" <XXXX@XXXXX.COM>wrote in
message news:XXXX@XXXXX.COM...
Quote
<<Fabio Santos:
The problem is when I try to run MS-Excel to edit another
spreadsheet when my app is running displaying the
spreadsheet in the OleContainer, I simply can't.
>>

Yes. There is a problem with using the TOleContainer if
other instances of Excel will be used. The best solution is
to use the OnDeactivate and OnActivate events of your
application to call Olecontainer.Close and
OleContainer.DoVerb (or Run) respectively. (NB it must be
the events of the application, not of the form - you can
use the TApplicationEvents component for this.) That way
when the user switched to Excel, the olecontainer would
close its instance of Excel - without losing its own
contents - and allow the other instance to function
normally.

One possible drawback is that OleContainer.Close saves the
workbook, but if you need to use TOleContainers and Excel
together I think you will have to live with that.

--
Deborah Pate (TeamB) delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html


 

Re:TOleContainer and Excel

<<Fabio Santos:
One more thing so, there is no way of using Excel while a
spreadsheet is open in an OleContainer, right? that is what
I wanted to be able to do.
Quote
>
FWIW you can easily start a separate issue of Excel while
the TOleContainer is running, if you run it by using the
Start menu. Trouble comes if you try to start it by
doubleclicking on a workbook. You can fix that simply by
changing the default action (Open) for the .xls file type
so that it doesn't use DDE.
That might be enough to solve your problem. But if it is
possible for the user to start your app when an existing
instance of Excel is already open, then you will have
problems again.
--
Deborah Pate (TeamB) delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html
 

Re:TOleContainer and Excel

Deborah, I appreciate all your help. I only have 2 more questions:
-How to display scrollbars within an OleContainer?
-The problems I am experiencing, is related to Excel itself or could
happen with any other application? It is a OLE 2 issue? Are there
alternatives?
Thank you so much!
"Deborah Pate (TeamB)" <XXXX@XXXXX.COM>wrote in
message news:XXXX@XXXXX.COM...
Quote
<<Fabio Santos:
One more thing so, there is no way of using Excel while a
spreadsheet is open in an OleContainer, right? that is what
I wanted to be able to do.
>>

FWIW you can easily start a separate issue of Excel while
the TOleContainer is running, if you run it by using the
Start menu. Trouble comes if you try to start it by
doubleclicking on a workbook. You can fix that simply by
changing the default action (Open) for the .xls file type
so that it doesn't use DDE.

That might be enough to solve your problem. But if it is
possible for the user to start your app when an existing
instance of Excel is already open, then you will have
problems again.

--
Deborah Pate (TeamB) delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html


 

Re:TOleContainer and Excel

<<Fabio Santos:
-How to display scrollbars within an OleContainer?
Quote
>
I'm not sure what your problem is here - they appear
automatically after DoVerb(ovShow), don't they?
<<Fabio:
-The problems I am experiencing, is related to Excel
itself or could happen with any other application?
Quote
>
Excel is particularly bad. The problem of starting a second
instance of Excel when the olecontainer is running doesn't
happen with other apps that I can think of. However the
problem when an olecontainer starts after an app is running
happens with other applications. An olecontainer uses a
running instance of an application, if it finds one in the
Running Object Table (ROT) when it starts up, so problems
with applications (such as MS Word) that register
themselves in the ROT are quite likely.
--
Deborah Pate (TeamB) delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html
 

Re:TOleContainer and Excel

Quote
<<Fabio Santos:
-How to display scrollbars within an OleContainer?
>>

I'm not sure what your problem is here - they appear
automatically after DoVerb(ovShow), don't they?

Sorry, the scrollbars appear normally but someone who wrote the app I am
maintaining now supressed other workbooks and the scrollbars.
Thanks!