I'm working on an app to parse Excel files. I need to remove invalid characters in column 2 and then in column 3 I need to trim and upper that column.
Any ideas?
Dim sql As String
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
' xlApp = New Excel.ApplicationClass
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open("c:\test13.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
sql = "SELECT * FROM [Sheet1$]"
[B] 'Remove Invalid Characters in Column 2[/B]
xlWorkSheet.Cells(2:2) {",", "%", "#", "a", "b", "c"} and Trim(vbUpperCase)
[B][U]'Remove Invalid Characters in Column 3[/U][/B]
xlWorkSheet.Cells(3:3) trim(upper)
xlWorkBook.Close()
'xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
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