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

using excel in .net

I am using a datagrid to populate a spreadhseet. The code
works fine (posted below formated to fit in this box, any
suggestions/better way let me know). The problem is that
the excel instance is not being destroyed. This is an
asp.net application using vb.net

Dim x As Integer
Dim s As String
Dim objExcel As New Excel.Application()

Try
With objExcel
.Visible = False
.Workbooks.Open("C:\WITemplates\WIReports.xlt")

For x = 1 To dgAnomaly.Items.Count
.Cells(x, 1) = dgAnomaly.Items.Item(x - 1).Cells(0).Text
.Cells(x, 2) = dgAnomaly.Items.Item(x - 1).Cells(1).Text
.Cells(x, 3) = dgAnomaly.Items.Item(x - 1).Cells(2).Text
.Cells(x, 4) = dgAnomaly.Items.Item(x - 1).Cells(3).Text
.Cells(x, 5) = dgAnomaly.Items.Item(x - 1).Cells(4).Text
.Cells(x, 6) = dgAnomaly.Items.Item(x - 1).Cells(5).Text
Next
End With
objExcel.ActiveWorkbook.SaveAs("c:\test.xls")
Catch obj As Exception
s = obj.Message
Finally
objExcel.Quit()
objExcel = Nothing
End Try
Jul 21 '05 #1
1 4637
I think this will fix your problem. Try changing your finally block to this:

objExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objExcel)
objExcel = Nothing

Here is a link with more information:

http://support.microsoft.com/?kbid=306682

--
Rob Windsor
G6 Consulting
Toronto, Canada
"billj" <wi***********@jabil.com> wrote in message
news:02****************************@phx.gbl...
I am using a datagrid to populate a spreadhseet. The code
works fine (posted below formated to fit in this box, any
suggestions/better way let me know). The problem is that
the excel instance is not being destroyed. This is an
asp.net application using vb.net

Dim x As Integer
Dim s As String
Dim objExcel As New Excel.Application()

Try
With objExcel
.Visible = False
.Workbooks.Open("C:\WITemplates\WIReports.xlt")

For x = 1 To dgAnomaly.Items.Count
.Cells(x, 1) = dgAnomaly.Items.Item(x - 1).Cells(0).Text
.Cells(x, 2) = dgAnomaly.Items.Item(x - 1).Cells(1).Text
.Cells(x, 3) = dgAnomaly.Items.Item(x - 1).Cells(2).Text
.Cells(x, 4) = dgAnomaly.Items.Item(x - 1).Cells(3).Text
.Cells(x, 5) = dgAnomaly.Items.Item(x - 1).Cells(4).Text
.Cells(x, 6) = dgAnomaly.Items.Item(x - 1).Cells(5).Text
Next
End With
objExcel.ActiveWorkbook.SaveAs("c:\test.xls")
Catch obj As Exception
s = obj.Message
Finally
objExcel.Quit()
objExcel = Nothing
End Try

Jul 21 '05 #2

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

Similar topics

0
by: Jeff | last post by:
I will start off by giving you a background of the process I am taking. The nature of my DTS package is that I recieve an Excel Spreadsheet, run it through the DTS Package applying validation to...
0
by: Mike Knight | last post by:
(I've also posted this problem on microsoft.public.excel.programming) I have a MS Access 2003 Database named "AS400 Fields.mdb". This database contains links to tables on an AS400. In MS...
4
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property...
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...
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...
5
by: kewalmehra | last post by:
Hi All, I have a requirement of saving Excel files as HTML using C#. I have managed to write code for saving as HTLM file. however this seems to be not working in the once perticular case . ...
5
by: Mike in Santa Rosa | last post by:
I'm trying to get a simple c# app built that can launch/manipulate an excel workbook, sheet. I've chased down several examples and can't any of them to work. So I must be doing somethnig obviouslt...
3
by: akristensen | last post by:
I am new to this site, so be patient if I do not ask the question correctly. Current Target Platform: Browser: MS IE, script language: Javascript (will use VBScript, but JS is preferred), External...
0
by: wankhusairi | last post by:
hallo sir .. i am still new on using vb and i have tried to load an excel using a visual basic interface.. but if i wanted to plot my excel data what should i do.. must i cahnge my program on loading...
7
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post by:
I have a vb.net app that opens an excel worksheet, reads data and then closes the sheet. Im noticing that the Excel process is still running after I have closed and disposed of my excel objects. ...
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
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.