Sto creando un file excel utilizzando interop.excel e il processo non si sta chiudendo. Questo è il codice che sto cercando di usare.Il processo Excel non si chiude in VB.net
Private Sub converToExcel(fileLoc As String, ds As DataSet)
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkBooks As Excel.Workbooks
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlApp = New Excel.Application
xlWorkBooks = xlApp.Workbooks
xlWorkBook = xlWorkBooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
xlWorkSheet.Columns.NumberFormat = "@"
xlWorkSheet.Cells(i + 1, j + 1) = String.Format("{0}", ds.Tables(0).Rows(i).Item(j).ToString())
Next
Next
xlWorkSheet.SaveAs(fileLoc)
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlWorkSheet)
releaseObject(xlWorkBook)
releaseObject(xlWorkBooks)
releaseObject(xlApp)
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Penso di mancare un oggetto COM ma non riesco a trovare una soluzione. Anche come nota, questo è in esecuzione su Windows 8 a 64 bit. Qualsiasi aiuto sarebbe fantastico! Grazie
e si è sicuri che questo non è un caso di sinistro dalla sperimentazione precedente? – Fionnuala
sì, controllo Task Manager dopo ogni test e rimuovo tutte le istanze di Excel. – jmcsmith
Non penso che questa sia la causa del tuo problema, ma 'releaseObject' potrebbe non fare tutto quello che pensi che faccia. Poiché stai passando 'obj'' ByVal', 'obj = Nothing' non ha alcun effetto sulle variabili' xlWorkSheet', 'xlWorkBook' ecc. – prprcupofcoffee