i am using EXCEL objects in a web apllication to pupulate data from a excel file. i am using code
Dim table(,) As String
Dim i, j As Integer
Dim xApp As New Excel.Application
Dim xWBS As Workbooks = xApp.Workbooks
Dim xWB As Workbook
Dim xWS As Excel.Worksheet
Dim xWSS As Object
xWBS.Open(FilePath)
xWB = xWBS.Item(1)
xWSS = xWB.Worksheets
xWS = xWSS.Item(1)
Dim xRange As Excel.Range
xRange = xWS.UsedRange
Dim xCols As Object = xRange.Columns
Dim xRows As Object = xRange.Rows
Dim xRowCount As Integer
xRowCount = xRows.Count
Dim xColCount As Integer
xColCount = xCols.Count
Dim inti, intj, iRow, iCol As Integer
iRow = 0
iCol = 0
ReDim table(xRowCount, xColCount)
For inti = 1 To xRowCount + 1
For intj = 1 To xColCount
table(iRow, iCol) = xRows(inti).Cells(intj).Text.ToString()
table(iRow, iCol) = table(iRow, iCol).Replace("'", "''")
iCol += 1
Next
iCol = 0
iRow += 1
Next
xWBS.Close()
xApp.Quit()
ReleaseComObject(table)
ReleaseComObject(xRows)
ReleaseComObject(xCols)
ReleaseComObject(xRange)
ReleaseComObject(xWSS)
ReleaseComObject(xWS)
ReleaseComObject(xWBS)
ReleaseComObject(xWB)
ReleaseComObject(xApp)
Private Sub ReleaseComObject(ByRef Reference As Object)
Try
Do Until System.Runtime.InteropServices.Marshal.ReleaseComO bject(Reference) <= 0
Loop
Catch
Finally
Reference = Nothing
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
End Try
End Sub
it is working fine if i don't use this code
For inti = 1 To xRowCount + 1
For intj = 1 To xColCount
table(iRow, iCol) = xRows(inti).Cells(intj).Text.ToString()
table(iRow, iCol) = table(iRow, iCol).Replace("'", "''")
iCol += 1
Next
iCol = 0
iRow += 1
Next
when i use this code to read data from excel file then the EXCEL process stays in memory.
can anyone help
khizar,lahore,pakistan
