读书人

vb.net操作完excel之后为什么总是生

发布时间: 2012-01-15 22:57:49 作者: rapoo

vb.net操作完excel之后,为什么总是生成无法杀掉的excel进程?如何解决?着急~~谢谢。
代码如下:
Dim xlApp As New Excel.Application '创建一个excel应用程序对象
Dim xlBooks As Excel.Workbooks '声明一个workbooks对象
Dim xlbook As Excel.Workbook '声明一个xlbook对象
Dim xlSheets As Excel.Sheets
Dim xlSheet As Excel.Worksheet '声明一个xlSheet对象
Dim sheetlist As New ArrayList
xlBooks = xlApp.Workbooks

Dim spath, strpath As String
xlbook = xlBooks.Add
strpath = "\养护报表\修保养工程数量表.xls "
spath = Server.MapPath(strpath)
xlbook = xlBooks.Open(spath)

xlSheet = xlbook.Worksheets.Item(1)
sheetlist.Add(xlSheet)
xlSheet.Activate() '-----------------------------------------------打开sheet1

Dim conn As OleDbConnection
conn = dbcon.createcon
conn.Open()
Dim cmm As New OleDbCommand
cmm.Connection = conn

Dim no, name, unit, remark As String
Dim i As Int32
With xlSheet
For i = 453 To 453
Dim a As Excel.Range = .Cells(i, 1)
Dim b As Excel.Range = .Cells(i, 2)
Dim c As Excel.Range = .Cells(i, 3)
Dim d As Excel.Range = .Cells(i, 7)

no = CType(a.Value, String)


name = CType(b.Value, String)
unit = CType(c.Value, String)
remark = CType(d.Value, String)

cmm.CommandText = "insert into fixproject(number,fname,unit,remark) values( ' " & no & " ', ' " & name & " ', ' " & unit & " ', ' " & remark & " ') "
cmm.ExecuteNonQuery()
Next
End With

xlbook.Close(True)
xlApp.Quit()
xlSheet = Nothing
xlbook = Nothing
xlApp = Nothing

conn.Close()
Response.Write( "完成! ")

疑问:为什么运行之后总是存在excel进程?应该如何解决?着急,谢谢。

[解决办法]
'Dim proc As Process
'Dim procs() As Process = Process.GetProcessesByName( "excel ")
'Try
' For Each proc In procs
' If Not proc.CloseMainWindow() Then
' proc.Kill()
' End If
' Next
'Catch
'End Try

读书人网 >VB Dotnet

热点推荐