473,406 Members | 2,549 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,406 software developers and data experts.

C#, ASP.NET, MS Excel

Hello,
Please, if enaybody could help a little bit... Namely, I need to build C#
ASP.NET Web that opens some Template.xls, write something to it and then
closes it (and releases the objects). Well, what actually happens is that I
simply manage to open the Excel file (somewhere in the filesystem on the
server), then I manage even to write something to it, but when I release all
the object, there's always EXCEL.EXE in task manager on the server...

Could please someone tell me what's wrong that causes EXCEL.EXE to persist
even after all the GC?

Here's some example:

System.Threading.Thread.CurrentThread.CurrentCultu re =
System.Globalization.CultureInfo.CreateSpecificCul ture("en-US");
Excel.Application objExcel = new Excel.Application();
Excel.Workbooks objWorkbooks = objExcel.Workbooks;
System.Reflection.Missing objMissingValue = System.Reflection.Missing.Value;
String strTemplateFile = "C:\\Test.xls";
Excel.Workbook objCurrentWorkbook = objWorkbooks.Open(strTemplateFile,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue);
Excel.Sheets objExcelSheets = objCurrentWorkbook.Worksheets;
objExcel.UserControl=true;
objExcel.Visible=true;
string currentSheet = "Sheet1";
Excel.Worksheet objExcelCurrentWorksheet =
(Excel.Worksheet)objExcelSheets.get_Item(currentSh eet);
Excel.Range objExcelRange =
(Excel.Range)objExcelCurrentWorksheet.get_Range("C 4", "C4");
this.LabelCreateExcel.Text = ((string)objExcelRange.Value2);
objExcelRange.Value2 = "Blabla!";
objExcelCurrentWorksheet.Cells[1, 1] = "test sheet";
objExcelCurrentWorksheet.get_Range("A1", "A1").Font.Bold = true;
objExcelCurrentWorksheet.get_Range("A3", "F3").EntireColumn.AutoFit();
// GC ... I destroy everything but no success :((
objExcel.Quit();
Marshal.ReleaseComObject(objWorkbooks);
Marshal.ReleaseComObject(objCurrentWorkbook);
Marshal.ReleaseComObject(objExcelSheets);
Marshal.ReleaseComObject(objExcelCurrentWorksheet) ;
Marshal.ReleaseComObject(objExcelRange);
Marshal.ReleaseComObject(objExcel);
objWorkbooks = null;
objCurrentWorkbook = null;
objExcelSheets = null;
objExcelCurrentWorksheet = null;
objExcelRange = null;
objExcel = null;
GC.Collect();
Thank you,

/Denis
Nov 16 '05 #1
4 1826
Denis,

I've seen this before... What happens is the Excel quit command seems to
close the document down, but leave a blank instance of Excel open. The catch
is this blank instance appears to lock up.

try the shutdown method in this
http://www.thescarms.com/dotNet/ExcelObject.asp

Thanks
Daniel.
"Denis Brkljacic" <de***********@nospam.hr> wrote in message
news:ct**********@fegnews.vip.hr...
Hello,
Please, if enaybody could help a little bit... Namely, I need to build C#
ASP.NET Web that opens some Template.xls, write something to it and then
closes it (and releases the objects). Well, what actually happens is that
I
simply manage to open the Excel file (somewhere in the filesystem on the
server), then I manage even to write something to it, but when I release
all
the object, there's always EXCEL.EXE in task manager on the server...

Could please someone tell me what's wrong that causes EXCEL.EXE to persist
even after all the GC?

Here's some example:

System.Threading.Thread.CurrentThread.CurrentCultu re =
System.Globalization.CultureInfo.CreateSpecificCul ture("en-US");
Excel.Application objExcel = new Excel.Application();
Excel.Workbooks objWorkbooks = objExcel.Workbooks;
System.Reflection.Missing objMissingValue =
System.Reflection.Missing.Value;
String strTemplateFile = "C:\\Test.xls";
Excel.Workbook objCurrentWorkbook = objWorkbooks.Open(strTemplateFile,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue);
Excel.Sheets objExcelSheets = objCurrentWorkbook.Worksheets;
objExcel.UserControl=true;
objExcel.Visible=true;
string currentSheet = "Sheet1";
Excel.Worksheet objExcelCurrentWorksheet =
(Excel.Worksheet)objExcelSheets.get_Item(currentSh eet);
Excel.Range objExcelRange =
(Excel.Range)objExcelCurrentWorksheet.get_Range("C 4", "C4");
this.LabelCreateExcel.Text = ((string)objExcelRange.Value2);
objExcelRange.Value2 = "Blabla!";
objExcelCurrentWorksheet.Cells[1, 1] = "test sheet";
objExcelCurrentWorksheet.get_Range("A1", "A1").Font.Bold = true;
objExcelCurrentWorksheet.get_Range("A3", "F3").EntireColumn.AutoFit();
// GC ... I destroy everything but no success :((
objExcel.Quit();
Marshal.ReleaseComObject(objWorkbooks);
Marshal.ReleaseComObject(objCurrentWorkbook);
Marshal.ReleaseComObject(objExcelSheets);
Marshal.ReleaseComObject(objExcelCurrentWorksheet) ;
Marshal.ReleaseComObject(objExcelRange);
Marshal.ReleaseComObject(objExcel);
objWorkbooks = null;
objCurrentWorkbook = null;
objExcelSheets = null;
objExcelCurrentWorksheet = null;
objExcelRange = null;
objExcel = null;
GC.Collect();
Thank you,

/Denis

Nov 16 '05 #2
Thanks!

But, I wouldn't say that only Excel is up (and doc itself closed), because
after I quit the Excel, then try to open the document, it says that this
document is currently used by another user (IUSR_*). After I manually kill
the EXCEL.EXE in task manager, file can be opened with no problem...
"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Denis,

I've seen this before... What happens is the Excel quit command seems to
close the document down, but leave a blank instance of Excel open. The catch is this blank instance appears to lock up.

try the shutdown method in this
http://www.thescarms.com/dotNet/ExcelObject.asp

Thanks
Daniel.
"Denis Brkljacic" <de***********@nospam.hr> wrote in message
news:ct**********@fegnews.vip.hr...
Hello,
Please, if enaybody could help a little bit... Namely, I need to build C# ASP.NET Web that opens some Template.xls, write something to it and then
closes it (and releases the objects). Well, what actually happens is that I
simply manage to open the Excel file (somewhere in the filesystem on the
server), then I manage even to write something to it, but when I release
all
the object, there's always EXCEL.EXE in task manager on the server...

Could please someone tell me what's wrong that causes EXCEL.EXE to persist even after all the GC?

Here's some example:

System.Threading.Thread.CurrentThread.CurrentCultu re =
System.Globalization.CultureInfo.CreateSpecificCul ture("en-US");
Excel.Application objExcel = new Excel.Application();
Excel.Workbooks objWorkbooks = objExcel.Workbooks;
System.Reflection.Missing objMissingValue =
System.Reflection.Missing.Value;
String strTemplateFile = "C:\\Test.xls";
Excel.Workbook objCurrentWorkbook = objWorkbooks.Open(strTemplateFile,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue, objMissingValue, objMissingValue,
objMissingValue, objMissingValue);
Excel.Sheets objExcelSheets = objCurrentWorkbook.Worksheets;
objExcel.UserControl=true;
objExcel.Visible=true;
string currentSheet = "Sheet1";
Excel.Worksheet objExcelCurrentWorksheet =
(Excel.Worksheet)objExcelSheets.get_Item(currentSh eet);
Excel.Range objExcelRange =
(Excel.Range)objExcelCurrentWorksheet.get_Range("C 4", "C4");
this.LabelCreateExcel.Text = ((string)objExcelRange.Value2);
objExcelRange.Value2 = "Blabla!";
objExcelCurrentWorksheet.Cells[1, 1] = "test sheet";
objExcelCurrentWorksheet.get_Range("A1", "A1").Font.Bold = true;
objExcelCurrentWorksheet.get_Range("A3", "F3").EntireColumn.AutoFit();
// GC ... I destroy everything but no success :((
objExcel.Quit();
Marshal.ReleaseComObject(objWorkbooks);
Marshal.ReleaseComObject(objCurrentWorkbook);
Marshal.ReleaseComObject(objExcelSheets);
Marshal.ReleaseComObject(objExcelCurrentWorksheet) ;
Marshal.ReleaseComObject(objExcelRange);
Marshal.ReleaseComObject(objExcel);
objWorkbooks = null;
objCurrentWorkbook = null;
objExcelSheets = null;
objExcelCurrentWorksheet = null;
objExcelRange = null;
objExcel = null;
GC.Collect();
Thank you,

/Denis


Nov 16 '05 #3
its one of the reasons to stay away from server-side automation of excel.
You may want to consider using the Office Web Components which has a
well-behaved Excel object included.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------
"Denis Brkljacic" <de***********@nospam.hr> wrote in message
news:ct**********@fegnews.vip.hr...
Thanks!

But, I wouldn't say that only Excel is up (and doc itself closed), because
after I quit the Excel, then try to open the document, it says that this
document is currently used by another user (IUSR_*). After I manually kill
the EXCEL.EXE in task manager, file can be opened with no problem...
"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Denis,

I've seen this before... What happens is the Excel quit command seems to
close the document down, but leave a blank instance of Excel open. The

catch
is this blank instance appears to lock up.

try the shutdown method in this
http://www.thescarms.com/dotNet/ExcelObject.asp

Thanks
Daniel.
"Denis Brkljacic" <de***********@nospam.hr> wrote in message
news:ct**********@fegnews.vip.hr...
> Hello,
>
>
> Please, if enaybody could help a little bit... Namely, I need to build C# > ASP.NET Web that opens some Template.xls, write something to it and
> then
> closes it (and releases the objects). Well, what actually happens is that > I
> simply manage to open the Excel file (somewhere in the filesystem on
> the
> server), then I manage even to write something to it, but when I
> release
> all
> the object, there's always EXCEL.EXE in task manager on the server...
>
> Could please someone tell me what's wrong that causes EXCEL.EXE to persist > even after all the GC?
>
> Here's some example:
>
> System.Threading.Thread.CurrentThread.CurrentCultu re =
> System.Globalization.CultureInfo.CreateSpecificCul ture("en-US");
> Excel.Application objExcel = new Excel.Application();
> Excel.Workbooks objWorkbooks = objExcel.Workbooks;
> System.Reflection.Missing objMissingValue =
> System.Reflection.Missing.Value;
> String strTemplateFile = "C:\\Test.xls";
> Excel.Workbook objCurrentWorkbook = objWorkbooks.Open(strTemplateFile,
> objMissingValue, objMissingValue, objMissingValue, objMissingValue,
> objMissingValue, objMissingValue, objMissingValue, objMissingValue,
> objMissingValue, objMissingValue, objMissingValue, objMissingValue,
> objMissingValue, objMissingValue);
> Excel.Sheets objExcelSheets = objCurrentWorkbook.Worksheets;
> objExcel.UserControl=true;
> objExcel.Visible=true;
> string currentSheet = "Sheet1";
> Excel.Worksheet objExcelCurrentWorksheet =
> (Excel.Worksheet)objExcelSheets.get_Item(currentSh eet);
> Excel.Range objExcelRange =
> (Excel.Range)objExcelCurrentWorksheet.get_Range("C 4", "C4");
> this.LabelCreateExcel.Text = ((string)objExcelRange.Value2);
> objExcelRange.Value2 = "Blabla!";
> objExcelCurrentWorksheet.Cells[1, 1] = "test sheet";
> objExcelCurrentWorksheet.get_Range("A1", "A1").Font.Bold = true;
> objExcelCurrentWorksheet.get_Range("A3", "F3").EntireColumn.AutoFit();
> // GC ... I destroy everything but no success :((
> objExcel.Quit();
> Marshal.ReleaseComObject(objWorkbooks);
> Marshal.ReleaseComObject(objCurrentWorkbook);
> Marshal.ReleaseComObject(objExcelSheets);
> Marshal.ReleaseComObject(objExcelCurrentWorksheet) ;
> Marshal.ReleaseComObject(objExcelRange);
> Marshal.ReleaseComObject(objExcel);
> objWorkbooks = null;
> objCurrentWorkbook = null;
> objExcelSheets = null;
> objExcelCurrentWorksheet = null;
> objExcelRange = null;
> objExcel = null;
> GC.Collect();
>
>
> Thank you,
>
> /Denis
>
>



Nov 16 '05 #4
Agreed. (!!!)

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:Oa*************@TK2MSFTNGP15.phx.gbl...
its one of the reasons to stay away from server-side automation of excel.
You may want to consider using the Office Web Components which has a
well-behaved Excel object included.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------
"Denis Brkljacic" <de***********@nospam.hr> wrote in message
news:ct**********@fegnews.vip.hr...
Thanks!

But, I wouldn't say that only Excel is up (and doc itself closed),
because
after I quit the Excel, then try to open the document, it says that this
document is currently used by another user (IUSR_*). After I manually
kill
the EXCEL.EXE in task manager, file can be opened with no problem...
"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in
message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Denis,

I've seen this before... What happens is the Excel quit command seems to
close the document down, but leave a blank instance of Excel open. The

catch
is this blank instance appears to lock up.

try the shutdown method in this
http://www.thescarms.com/dotNet/ExcelObject.asp

Thanks
Daniel.
"Denis Brkljacic" <de***********@nospam.hr> wrote in message
news:ct**********@fegnews.vip.hr...
> Hello,
>
>
> Please, if enaybody could help a little bit... Namely, I need to build

C#
> ASP.NET Web that opens some Template.xls, write something to it and
> then
> closes it (and releases the objects). Well, what actually happens is

that
> I
> simply manage to open the Excel file (somewhere in the filesystem on
> the
> server), then I manage even to write something to it, but when I
> release
> all
> the object, there's always EXCEL.EXE in task manager on the server...
>
> Could please someone tell me what's wrong that causes EXCEL.EXE to

persist
> even after all the GC?
>
> Here's some example:
>
> System.Threading.Thread.CurrentThread.CurrentCultu re =
> System.Globalization.CultureInfo.CreateSpecificCul ture("en-US");
> Excel.Application objExcel = new Excel.Application();
> Excel.Workbooks objWorkbooks = objExcel.Workbooks;
> System.Reflection.Missing objMissingValue =
> System.Reflection.Missing.Value;
> String strTemplateFile = "C:\\Test.xls";
> Excel.Workbook objCurrentWorkbook = objWorkbooks.Open(strTemplateFile,
> objMissingValue, objMissingValue, objMissingValue, objMissingValue,
> objMissingValue, objMissingValue, objMissingValue, objMissingValue,
> objMissingValue, objMissingValue, objMissingValue, objMissingValue,
> objMissingValue, objMissingValue);
> Excel.Sheets objExcelSheets = objCurrentWorkbook.Worksheets;
> objExcel.UserControl=true;
> objExcel.Visible=true;
> string currentSheet = "Sheet1";
> Excel.Worksheet objExcelCurrentWorksheet =
> (Excel.Worksheet)objExcelSheets.get_Item(currentSh eet);
> Excel.Range objExcelRange =
> (Excel.Range)objExcelCurrentWorksheet.get_Range("C 4", "C4");
> this.LabelCreateExcel.Text = ((string)objExcelRange.Value2);
> objExcelRange.Value2 = "Blabla!";
> objExcelCurrentWorksheet.Cells[1, 1] = "test sheet";
> objExcelCurrentWorksheet.get_Range("A1", "A1").Font.Bold = true;
> objExcelCurrentWorksheet.get_Range("A3", "F3").EntireColumn.AutoFit();
> // GC ... I destroy everything but no success :((
> objExcel.Quit();
> Marshal.ReleaseComObject(objWorkbooks);
> Marshal.ReleaseComObject(objCurrentWorkbook);
> Marshal.ReleaseComObject(objExcelSheets);
> Marshal.ReleaseComObject(objExcelCurrentWorksheet) ;
> Marshal.ReleaseComObject(objExcelRange);
> Marshal.ReleaseComObject(objExcel);
> objWorkbooks = null;
> objCurrentWorkbook = null;
> objExcelSheets = null;
> objExcelCurrentWorksheet = null;
> objExcelRange = null;
> objExcel = null;
> GC.Collect();
>
>
> Thank you,
>
> /Denis
>
>



Nov 16 '05 #5

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

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
9
by: Anthony | last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't really changed since the days of VB6. That is, I'd do something similar to this Code: Dim ExcelApp As...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.