473,385 Members | 1,343 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,385 software developers and data experts.

Orphaned Excel 97 Instances (C#)

howdy folks,

first off, I'd like to not that I have browsed the forums and thanks to
what I've found there I'm 80% through this problem, but the last part
seems to be a profound obstacle and any help you could provide would be
much appreciated.

As my title indicates, I'm devloping a C# application which will need
to opne up an excel template...manipulate and save it, and then quit.
The problem I'm having is that the instance of EXCEL.EXE remains open
even when I release all of the objects I manipulate, null them, and run
GC.Collect(). Many thanks to all of you who have posted on this topic
before or I wouldn't have even gotten as far as releasing/collecting
etc.

Here is a sample of code that exhibits the problem.

Excel.Application xlApp = new Excel.Application();
xlApp.Visible = false;

Excel.Workbook excelWorkbook = xlApp.Workbooks.Open(instring, 0, false,
5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0,
true);
Excel.Worksheet ws = (Excel.Worksheet)xlApp.Sheets[1];

for (i = 0; i<items.Count; i++)
{

//insert a column
Excel.Range rng = (Excel.Range)ws.Cells[3, 4];
Excel.Range column = rng.EntireColumn;

column.Insert(Excel.XlInsertShiftDirection.xlShift ToRight);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(column);
column = null;

//delete superfluous cells
rng = ws.get_Range("D5", "D11");
rng.Delete(Excel.XlDeleteShiftDirection.xlShiftToL eft);

rng = ws.get_Range("D41", "D55");
rng.Delete(Excel.XlDeleteShiftDirection.xlShiftToL eft);

//adjust formatting of inserted column
rng = ws.get_Range("D14", "D16");
rng.Merge(Type.Missing);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(rng);
rng = null;
}
excelWorkbook.SaveAs("c:\\Program
Files\\rpm\\incentive\\grouptemplates\\" + Companion_file_name +
".xlt", Excel.XlFileFormat.xlTemplate,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(ws);
ws = null;
excelWorkbook.Close(false, Type.Missing, Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(excelWorkbook);

xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(xlApp);
GC.Collect();
The previous code will successfully remove the instance if I don't
execute the

rng.Merge(Type.Missing);

line. Otherwise the Excel instance remains.

Is there a way I can find out what COM objects are open so I know which
ones I am implicitly opening and not releasing? Is there a problem
with reusing the range object (I've tried nulling it before assigning a
different value to it, but with no luck). Are there other actions I
should be taking? Many thanks for any help anyone can give,

-rhett

Nov 18 '05 #1
0 1202

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

Similar topics

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: Gary Cobden | last post by:
Hi I have a routine that uses VBA to open a hidden occurence of Excel, and do background computations. However, in the event that the routine terminates abnormally, I have not been able to...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
0
by: Rich Wallace | last post by:
Hello all, Looking for suggestions and tips if possible. I have an application running on a file server that utilizes the FileSystemWatcher to trap when any Excel files are saved by a user. I...
4
by: Powerguy | last post by:
Hi all, I've spent countless hours trying to get this silly EXCEL process to close once I have used it. If anyone can help it would really REALLy be appreciated! Below is my code- Dim t As...
2
by: Powerguy | last post by:
Hi all, I am looking for a way to get the Process id (or a handle) of an EXCEL process created from within my code. For example when the following code is executed: Dim EXL As...
21
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the...
19
by: wreckingcru | last post by:
I'm trying to output a SQL query that is constructed thru my VB.net GUI into an excel file. Here is the code I'm using: 'Sqlstmt is the SQL query statement 'Conn is the SQL Connection object...
24
rauty
by: rauty | last post by:
Hi all, I'm trying to access the most recent instance of Excel so I can paste data. What works for me is if Excel isn't already opened, I open it and can paste the data where I want to. What...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.