473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Excel, .Net and threads

I have been asked by a client to produce a proof of concept of how .Net performs and works within an Excel workbook. Everything works perfectly with all the required events firing and data being read from the correct cells.
I sent this to the client and he is happy but asked some questions, and Im not too sure on the answers (he is an old school VBA developer at heart and doesn't know anything about .Net):

--------------------------------------------------------------------------------

The only potential issue is whether the menu is calling the same thread of the .NET class or a new thread. I suspect it is the same thread each time (good) and assume that your core .NET class is declared global-static as there is no memory churn when the menus and events are running. The problem we had with Excel 97 was that it did not support global static classes and therefore any variable that needed to be a global variable was not necessarily global. The use of a static function to instantiate the class was the workaround.

--------------------------------------------------------------------------------

I believe that everything is running in the same thread and their is only one instance of the Application and WorkBook objects.
Can somone please confirm or deny these statements.
Thanks
Nov 19 '05 #1
5 1551
Hi Graham,

AS for the
=========
.Net performs and works within an Excel workbook
=========

you mentioned, do you means using .NET to Automate the office Excel
workbook or use .NET based add-in components or something like the .net
based SmartDoc interfaces?

For .NET based Automation code, they're just a managed wrapper of the COM
interfaces All the instances are created by the underlying COM
infrastructure and be wrappered by managed code so as to make use of the
managed programming language's feature.

For those .NET based Add-in or SMARTDoc compoenents, they're hosted inside
the word/excel's unmanaged process, but be separated from the unmanaged
code. All the managed class instances or controls be controled in CLR
runtime (managed thread/ heaps....). Of course, all the Control and their
events will be fired in the same UI thread.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Graham" <en*******@newsgroups.nospam>
| Subject: Excel, .Net and threads
| Date: Mon, 19 Sep 2005 14:27:13 +1200
| Lines: 91
| MIME-Version: 1.0
| Content-Type: multipart/alternative;
| boundary="----=_NextPart_000_001C_01C5BD26.3A40CF60"
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <OR**************@TK2MSFTNGP15.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 222-153-55-149.jetstream.xtra.co.nz 222.153.55.149
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125412
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have been asked by a client to produce a proof of concept of how .Net
performs and works within an Excel workbook. Everything works perfectly
with all the required events firing and data being read from the correct
cells.
| I sent this to the client and he is happy but asked some questions, and
Im not too sure on the answers (he is an old school VBA developer at heart
and doesn't know anything about .Net):
|
----------------------------------------------------------------------------
----
| The only potential issue is whether the menu is calling the same thread
of the .NET class or a new thread. I suspect it is the same thread each
time (good) and assume that your core .NET class is declared global-static
as there is no memory churn when the menus and events are running. The
problem we had with Excel 97 was that it did not support global static
classes and therefore any variable that needed to be a global variable was
not necessarily global. The use of a static function to instantiate the
class was the workaround.
|
----------------------------------------------------------------------------
----
| I believe that everything is running in the same thread and their is only
one instance of the Application and WorkBook objects.
| Can somone please confirm or deny these statements.
| Thanks
|

Nov 19 '05 #2
Im using Visual Studio Tools for Office 2003 and creating a new workbook
project in Visual Studio,
so I think its "using .Net to automate the office Excel workbook", is this
right?
Graham
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:rr**************@TK2MSFTNGXA01.phx.gbl...
Hi Graham,

AS for the
=========
.Net performs and works within an Excel workbook
=========

you mentioned, do you means using .NET to Automate the office Excel
workbook or use .NET based add-in components or something like the .net
based SmartDoc interfaces?

For .NET based Automation code, they're just a managed wrapper of the COM
interfaces All the instances are created by the underlying COM
infrastructure and be wrappered by managed code so as to make use of the
managed programming language's feature.

For those .NET based Add-in or SMARTDoc compoenents, they're hosted inside
the word/excel's unmanaged process, but be separated from the unmanaged
code. All the managed class instances or controls be controled in CLR
runtime (managed thread/ heaps....). Of course, all the Control and their
events will be fired in the same UI thread.

Thanks,

Steven Cheng
Microsoft Online Support

Nov 19 '05 #3
Hi

The VSTO approach is similar with Automation, it does use the Office Object
Modal to manipulate the Office Application.
Based on my research, the VBA approach/VSTO code behind apporach will run
the code all on the Excel UI thread.
e.g. We will try to popup a msgbox in a VBA macro or in the VSTO code
behind, they will all run on the Excel UI thread, commonly it is the first
thread in the process.

For the VSTO in .NET, when the Excel is loaded, it will try to check
certain properties in the document and try to load the CLR to host the
managed dll. Because the Office Code behind code is managed code, it will
only run in the CLR, and then the CLR will JIT it into unmanaged code to
run. This is how CLR/.NET works. So the .NET class is inside the CLR, it is
host CLR in the Excel process to run the managed code.

For detailed information about CLR hosting, I recommend you may take a look
at the book below which explained that.
Customizing the Microsoft .NET Framework Common Language Runtime
(Pro-Developer (Paperback)) (Paperback)
http://www.amazon.com/exec/obidos/tg...672265-1264963
?v=glance

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 19 '05 #4
Thank you both for your helpful answers

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:kR*************@TK2MSFTNGXA01.phx.gbl...
Hi

The VSTO approach is similar with Automation, it does use the Office
Object
Modal to manipulate the Office Application.
Based on my research, the VBA approach/VSTO code behind apporach will run
the code all on the Excel UI thread.
e.g. We will try to popup a msgbox in a VBA macro or in the VSTO code
behind, they will all run on the Excel UI thread, commonly it is the first
thread in the process.

For the VSTO in .NET, when the Excel is loaded, it will try to check
certain properties in the document and try to load the CLR to host the
managed dll. Because the Office Code behind code is managed code, it will
only run in the CLR, and then the CLR will JIT it into unmanaged code to
run. This is how CLR/.NET works. So the .NET class is inside the CLR, it
is
host CLR in the Excel process to run the managed code.

For detailed information about CLR hosting, I recommend you may take a
look
at the book below which explained that.
Customizing the Microsoft .NET Framework Common Language Runtime
(Pro-Developer (Paperback)) (Paperback)
http://www.amazon.com/exec/obidos/tg...672265-1264963
?v=glance

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 19 '05 #5
You're welcome Graham,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Graham" <en*******@newsgroups.nospam>
| References: <OR**************@TK2MSFTNGP15.phx.gbl>
<rr**************@TK2MSFTNGXA01.phx.gbl>
<Oq**************@TK2MSFTNGP10.phx.gbl>
<kR*************@TK2MSFTNGXA01.phx.gbl>
| Subject: Re: Excel, .Net and threads
| Date: Thu, 22 Sep 2005 11:59:59 +1200
| Lines: 42
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <eg**************@TK2MSFTNGP14.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 222-153-144-23.jetstream.xtra.co.nz 222.153.144.23
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:126274
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thank you both for your helpful answers
|
| ""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
| news:kR*************@TK2MSFTNGXA01.phx.gbl...
| > Hi
| >
| > The VSTO approach is similar with Automation, it does use the Office
| > Object
| > Modal to manipulate the Office Application.
| > Based on my research, the VBA approach/VSTO code behind apporach will
run
| > the code all on the Excel UI thread.
| > e.g. We will try to popup a msgbox in a VBA macro or in the VSTO code
| > behind, they will all run on the Excel UI thread, commonly it is the
first
| > thread in the process.
| >
| > For the VSTO in .NET, when the Excel is loaded, it will try to check
| > certain properties in the document and try to load the CLR to host the
| > managed dll. Because the Office Code behind code is managed code, it
will
| > only run in the CLR, and then the CLR will JIT it into unmanaged code to
| > run. This is how CLR/.NET works. So the .NET class is inside the CLR,
it
| > is
| > host CLR in the Excel process to run the managed code.
| >
| > For detailed information about CLR hosting, I recommend you may take a
| > look
| > at the book below which explained that.
| > Customizing the Microsoft .NET Framework Common Language Runtime
| > (Pro-Developer (Paperback)) (Paperback)
| >
http://www.amazon.com/exec/obidos/tg...672265-1264963
| > ?v=glance
| >
| > Best regards,
| >
| > Peter Huang
| > Microsoft Online Partner Support
| >
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "AS IS" with no warranties, and confers no
| > rights.
| >
|
|
|

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sylvia | last post by:
Dear All, Would appreciate if someone can help me out on this. I have an Excel Add-in which is only available on the web server. The Add-in allows user to retrieve data from a proprietary...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
1
by: Rick Brown | last post by:
After reading 30+ threads on the subject and implementing pertinent changes I still have an instance of Excel that won't close. I hope its due to my poor coding and someone can spot the error....
13
by: aleksandra_83 | last post by:
Hello, I have searched all over google groups and internet, but I have not found a solution to this problem that has worked. The solutions I found helped me single out the line that is causing...
10
by: KeithRaginF | last post by:
Hello I am trying to return the contents of an Excel file. However, I don't want to just redirect the request to the Excel file since it does not reside in a location where that is appropriate. ...
2
by: Brandon | last post by:
Hi all, I'm currently working on a project where we have a need to expose an Excel spreadsheet on the web as a webservice that needs to be reliable and available 24x7x365. I've implemented a...
2
by: sfeinst | last post by:
I am trying to access Excel spreadsheets to modify data from a VB.NET application. If I have an object defined as: Public Class Test Private _excel As Microsoft.Office.Interop.Excel.Application...
3
by: Chris | last post by:
I have a python script that is driving Excel and using the win32com module. However, upon program completion there's still an Excel.exe process running in the background that I must terminate...
0
by: Jon Delano | last post by:
Hello All I am working a on web application created in Visual Studio 2005 VB. It has to do some work with Excel files, so I created a DLL in VS2005. My development machine is XP SP3. When my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.