程序大致如下:
Dim xlApp As New Excel.Application()
Dim obook As Excel.Workbooks = xlApp.Workbooks
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet Dim rowIndex As Integer = 1
Dim colIndex As Integer = 0
xlBook = obook.Add
xlSheet = xlBook.ActiveSheet
。 xlSheet.Range("b2").Value = countername
xlSheet.Range("c6").Value = CStr(year - 1)
xlSheet.Range("d6").Value = CStr(year - 2)
xlSheet.Range("e6").Value = "增长%"
xlSheet.Range("f6").Value = CStr(year - 3)
xlSheet.Range("g6").Value = "增长%"
xlSheet.Range("h6").Value = CStr(year) & "Q1"
xlSheet.Range("i6").Value = CStr(year) & "Q2"
xlSheet.Range("j6").Value = CStr(year) & "Q3"
xlSheet.Range("k6").Value = CStr(year) & "Q4"
xlSheet.Range("l6").Value = CStr(year) & "TTL"
xlSheet.Range("m6").Value = "增长%"。 xlSheet.Range("a18:m20").Select()
xlApp.Selection.mergecells = True
xlSheet.Range("a18").Value = myReader.GetString(26)
xlApp.Workbooks(1).SaveAs(filename)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
xlSheet = Nothing
xlBook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
xlBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(obook)
obook = Nothing
'xlApp.Workbooks.Close()
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlApp = Nothing GC.Collect()这样这段代码,怎么excel进程始终无法释放。那位指点一下!!
Dim xlApp As New Excel.Application()
Dim obook As Excel.Workbooks = xlApp.Workbooks
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet Dim rowIndex As Integer = 1
Dim colIndex As Integer = 0
xlBook = obook.Add
xlSheet = xlBook.ActiveSheet
。 xlSheet.Range("b2").Value = countername
xlSheet.Range("c6").Value = CStr(year - 1)
xlSheet.Range("d6").Value = CStr(year - 2)
xlSheet.Range("e6").Value = "增长%"
xlSheet.Range("f6").Value = CStr(year - 3)
xlSheet.Range("g6").Value = "增长%"
xlSheet.Range("h6").Value = CStr(year) & "Q1"
xlSheet.Range("i6").Value = CStr(year) & "Q2"
xlSheet.Range("j6").Value = CStr(year) & "Q3"
xlSheet.Range("k6").Value = CStr(year) & "Q4"
xlSheet.Range("l6").Value = CStr(year) & "TTL"
xlSheet.Range("m6").Value = "增长%"。 xlSheet.Range("a18:m20").Select()
xlApp.Selection.mergecells = True
xlSheet.Range("a18").Value = myReader.GetString(26)
xlApp.Workbooks(1).SaveAs(filename)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
xlSheet = Nothing
xlBook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
xlBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(obook)
obook = Nothing
'xlApp.Workbooks.Close()
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlApp = Nothing GC.Collect()这样这段代码,怎么excel进程始终无法释放。那位指点一下!!
Public Sub KillExcelProcess()
Dim p As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")(0)
p.Kill()
End Sub