B
billj
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
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