使用 Excel 过滤器或 vb.net 过滤 Excel 行
Filter Excel rows using Excel filter or vb.net
我有 17728 行这种格式,我只需要保留包含 "User active"、"First Name"、姓氏"、"Group"、"24 位卡代码" 的行,和“8,16 位卡代码”。
喜欢:
用户活跃:是
名字:Pharma
姓氏:访客 1
...
文件中的所有 17728 行。
有没有办法通过行数来做到这一点?
如果我们为 "User active" 取第 3 行并加上 19,我们将落在第二 "User active" 行。
或者还有其他解决方案吗?
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim range As Excel.Range
Dim rCnt As Integer
Dim cCnt As Integer
Dim Obj As Object
xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("c:\vbexcel.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
range = xlWorkSheet.UsedRange
For rCnt = 1 To range.Rows.Count
For cCnt = 1 To range.Columns.Count
Obj = CType(range.Cells(rCnt, cCnt), Excel.Range)
MsgBox(Obj.value)
Next
Next
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
End Sub
End Class
来源:To read the entire worksheet in an Excel workbook through VB.net Code
我有 17728 行这种格式,我只需要保留包含 "User active"、"First Name"、姓氏"、"Group"、"24 位卡代码" 的行,和“8,16 位卡代码”。
喜欢:
用户活跃:是
名字:Pharma
姓氏:访客 1
...
文件中的所有 17728 行。
有没有办法通过行数来做到这一点?
如果我们为 "User active" 取第 3 行并加上 19,我们将落在第二 "User active" 行。 或者还有其他解决方案吗?
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim range As Excel.Range
Dim rCnt As Integer
Dim cCnt As Integer
Dim Obj As Object
xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("c:\vbexcel.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
range = xlWorkSheet.UsedRange
For rCnt = 1 To range.Rows.Count
For cCnt = 1 To range.Columns.Count
Obj = CType(range.Cells(rCnt, cCnt), Excel.Range)
MsgBox(Obj.value)
Next
Next
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
End Sub
End Class
来源:To read the entire worksheet in an Excel workbook through VB.net Code