Ch 20-22 Excel (Interop) Question

Forums, software downloads and discussions. THIS IS WHERE YOU HAVE TO FIND HOW TO REGISTER IN ORDER TO GET THE C# SOURCE CODE ACCOMPANYING THE BOOK. ONCE REGISTERED YOU WILL BE ADMITTED TO ANOTHER FORUM ("C# for Financial Markets Download Centre") WHERE YOU CAN DOWNLOAD THE CODE AND THE "HOW TO" INSTALLATION DOCUMENT.

Ch 20-22 Excel (Interop) Question

Postby sopko.16 » Fri May 03, 2013 7:42 pm

Hello,



Sorry in advance if this is an inappropriate area for this question. I also do not know what specific chapter this would technically be covered under. When I have worked with Excel Interop with this book as well as in the past I have noticed the following:



1.) Instances of excel stay open like "zombies" in the task manager even after they are closed by user.

-As far as I can see is a common problem for Excel and this code has it as well

-No big issue, but if I am incorrect and there is a solution in the codebase, please let me know.



I am curious to see if you have solved it since I have done a significant amount with Excel here, and still not found a best stable solution yet. My guess would be to overload some "on close" event to quit and dispose but I have not been able to find that yet.



2.) There does not appear to be a way to do the following:

A.) Open Excel, then whatever file you want

B.) Say you have a windows forms or WPF financial management front end- then have it setup so that you could click a button and attach to the excel process/ grab the Excel object model and work with the sheet if possible.



I believe that this is related to:

http://blogs.officezealot.com/whitechap ... /4514.aspx

Needing a "shimmed automation add-in in Excel"



My question here is:



Is it possible to do something similar to attach to a pre-opened excel instance outside of the cruddy running object table (ROT)?

-The ROT always returns "Excel" as "Excel" so you can only grab the first window always.

-Would WhiteChapel's shimming article posted above along with your add in sections be able to solve this problem

-Have you guys solved this problem/ do you have additional experience with it?



I also tried reflection, but I think it might suffer from similar issues as the ROT.



If you do not know, it is not a big deal. I figured I would ask since I have beaten my head into it many times, and I really like excel visualization tools, but they just need these mods to really be useful for live moving data matrices, tensors, etc in my opinion.



Thank you for your help,



Mike P. Sopko



Edit- I think it might be related to this:

http://www.pcreview.co.uk/forums/attach ... 93033.html



http://support.microsoft.com/kb/316126



But this also requires you to only have one instance of Excel open at a time. If I had multiples open, I could not say "grab workbook with this name: D_COPY (or D_COPY.xlsx) and have it use that as the target area. This is the point that I always get stuck at.
sopko.16
 
Posts: 4
Joined: Thu Mar 28, 2013 3:20 pm

Postby admin » Mon May 06, 2013 3:01 pm

Hi Mike,

Just off-hand, but a possibility is to use IDTExtensibility2 interface esp. with OnConnection() and OnDisconnection() that can be customised.



... maybe it's possible to close Excel then. (App.Quit?)



// I will have a deaper look and get back.
admin
Site Admin
 
Posts: 237
Joined: Thu Dec 07, 2006 4:03 pm
Location: Amsterdam, The Netherlands

Postby Cuchulainn » Fri May 10, 2013 7:12 pm

Here is a big book on Excel with VB.NET that might give some pointers.



http://www.amazon.com/Professional-Exce ... 0321508793
User avatar
Cuchulainn
 
Posts: 676
Joined: Mon Dec 18, 2006 2:48 pm
Location: Amsterdam, the Netherlands

Postby sopko.16 » Fri May 17, 2013 1:39 pm

Thanks for the heads up! I will look into that. Have you seen any c# oriented sources though?



This is great though, a welcome recommendation. I might just take the plunge and then support VB.NET and c#. I feel like if you know one decently, the other should not be that bad and calling into it should not be a problem since both are CLR.



Thanks,

Mike



I am still wondering about this, but I will attempt to work through further on my own:



2.) There does not appear to be a way to do the following:

A.) Open Excel, then whatever file you want

B.) Say you have a windows forms or WPF financial management front end- then have it setup so that you could click a button and attach to the excel process/ grab the Excel object model and work with the sheet if possible.



Is it possible to do something similar to attach to a pre-opened excel instance outside of the cruddy running object table (ROT)?

-The ROT always returns "Excel" as "Excel" so you can only grab the first window always.



If I figure something out also, I will post so that it can help others as well.
sopko.16
 
Posts: 4
Joined: Thu Mar 28, 2013 3:20 pm

Postby Cuchulainn » Mon May 20, 2013 11:41 am

It is is possible indeed to have VB.NET and C# in the same project so you could use the latter code as a black box and do all the rest in C#. Porting VB.NET to C# should be easy?



Since .NET is evolving it may be a good idea to keep abreast of MSDN and the posts on StackOverflow which in many cases are spot on.
User avatar
Cuchulainn
 
Posts: 676
Joined: Mon Dec 18, 2006 2:48 pm
Location: Amsterdam, the Netherlands

Re: Ch 20-22 Excel (Interop) Question

Postby kanita » Sat Dec 13, 2014 12:30 pm

There are two variants on the Box-Mueller trick. One throws away bad variates (the so called polar rejection method). The other uses trigonometric functions. I have found that it is hard to guage which is faster a priori.
kanita
 
Posts: 1
Joined: Sat Dec 13, 2014 12:07 pm

Re: Ch 20-22 Excel (Interop) Question

Postby Cuchulainn » Mon Dec 15, 2014 1:10 pm

You can try _profiling_ your code.
User avatar
Cuchulainn
 
Posts: 676
Joined: Mon Dec 18, 2006 2:48 pm
Location: Amsterdam, the Netherlands


Return to Official Site C# in Financial Markets (Duffy/Germani)

Who is online

Users browsing this forum: No registered users and 1 guest

cron