Running Excel from .NET
Running Excel from .NET
Running Excel from .NET
Running Excel from .NET
Running Excel from .NET
Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET
Running Excel from .NET Running Excel from .NET
Running Excel from .NET
Go Back  Xtreme Visual Basic Talk > > > Running Excel from .NET


Reply
 
Thread Tools Display Modes
  #1  
Old 03-29-2013, 07:17 AM
Shankar_R Shankar_R is offline
Newcomer
 
Join Date: Mar 2013
Posts: 4
Default Running Excel from .NET


Hi,

I am new to this forum. I have a VB.NET program (Visual Studio 2010 Express) that needs to run Excel 2010. I want to follow the steps outlined here.

But I am confused about how to go about using Marshal.FinalReleaseComObject for all the declared variables.

If I have several subs and functions that each have local Excel objects, do I need to use the above function at the end of each of them (that is, before the variables go out of scope)?

My program would read in nearly 200 spreadsheets serially and form a .NET data structure, so I would like to GC the COM objects at the end of closing each of them, to save runtime memory. I would want to delay the Marshal.FinalReleaseComObject for Excel itself till I am done processing all the spreadsheets.

Creating the data structure from the spreadsheet cells involves many subs and functions all over the place that I do not want to GC at the end of each of them. That will be thousands of times per file and will take a lot of time, besides hopelessly adding to the complexity of the code.

What I don't understand is, when declared Excel objects go out of scope, shouldn't they automatically get garbage collected? Can someone shed some light on this? Thanks.

Shankar
Reply With Quote
  #2  
Old 06-20-2013, 06:14 AM
blaisexena blaisexena is offline
Newcomer
 
Join Date: Jun 2013
Posts: 5
Default

Hi,
As far as I tested all msoffice applications including msword, powerpoint, mspublisher automation, excel is the most problematic application. As I noticed every application of msoffice has different divisions of programmers. Yes, they are automatically garbage, but we usually use GC as to think that they are not collected, because we are confused why it doesn't quit directly. MsExcel has a leak, or a bug. I doubt they are with msOffice 2013.

I don't think putting a lot of GC will resolved the issue of Excel, because every machine that excels ran has different issues, the most effective way to quit excel is to look for the specific filename that excel used.

Probably using Excel automation in a very simple way would quit normally.


''The way I tested this, seems to work, sometimes it closes all Excel
Quote:
For Each proc As Process In Process.GetProcessesByName('EXCEL')
If wproc.MainWindowTitle.Contains('noextfilename') Then
proc.Kill()
End If
Next
I'm not sure of this, but I think it will work with some few lines of code.
Quote:
For Each proces As Process In Process.GetProcesses
Dim windows As IDictionary(Of IntPtr, String) = GetOpenWindowsFromPID(proces.Id)
For Each kvp As KeyValuePair(Of IntPtr, String) In windows
If kvp.ToString.Contains("noextfilename") Then
Dim pro As Process = Process.GetProcessById(kvp.Key)
pro.Kill()
End If
Next
Next
Reply With Quote
  #3  
Old 06-20-2013, 06:16 AM
blaisexena blaisexena is offline
Newcomer
 
Join Date: Jun 2013
Posts: 5
Default

Sorry, where's my quick post?, I don't know why it's gone...
Ok to answer again directly, yes it is collected directly, we just though not because we use a lot of GC specially for excel. for me excel has a bug. I'm using the processID of the filename that uses excel to quit.

thanks, my other post was gone.
Reply With Quote
  #4  
Old 06-20-2013, 10:49 AM
blaisexena blaisexena is offline
Newcomer
 
Join Date: Jun 2013
Posts: 5
Default

Oh, I see my previous post, server problem? no way, I think I was blind for a couple of minutes. joke. anyway, thanks for reading.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Running Excel from .NET
Running Excel from .NET
Running Excel from .NET Running Excel from .NET
Running Excel from .NET
Running Excel from .NET
Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET Running Excel from .NET
Running Excel from .NET
Running Excel from .NET
 
Running Excel from .NET
Running Excel from .NET
 
-->