如何设置一个过滤器之前,我红色excel文件vb.net?

如何设置一个过滤器之前,我红色excel文件vb.net?,vb.net,excel,Vb.net,Excel,我有一个excel,有90.000行,但当我按“样本商店”筛选我的列“H1”时,我有2000行。我想读2000行而不是90000行。在vb.net中读取excel文件之前如何设置过滤器? 我的代码是: Do While currentWorksheet.Cells(i, 1).Value <> Nothing If workBook.Worksheets.Count > 0 Then Name = currentWorksheet.Cells(

我有一个excel,有90.000行,但当我按“样本商店”筛选我的列“H1”时,我有2000行。我想读2000行而不是90000行。在vb.net中读取excel文件之前如何设置过滤器? 我的代码是:

 Do While currentWorksheet.Cells(i, 1).Value <> Nothing
If workBook.Worksheets.Count > 0 Then
                Name = currentWorksheet.Cells(i, 1).Value
                DataSo = currentWorksheet.Cells(i, 33).Value
                Try
                    Dim Conv As Double = Double.Parse(DataSo)
                    Variable = DateTime.FromOADate(Conv).ToString("MMMM/dd/yyyy")
                Catch ex As Exception

                End Try

                Data1 = Convert.ToDateTime(BOX_Data1.Text)
                Data2 = Convert.ToDateTime(BOX_Data2.Text)

                If (currentWorksheet.Cells(i, 4).Value) = "Completed" And (currentWorksheet.Cells(i, 8).Value) = "RBT SAMPLE SHOP" Then

                    If Variable >= Data1 And Variable <= Data2 Then

                        If currentWorksheet.Cells(i, 35).Value <> Nothing Or currentWorksheet.Cells(i, 35).Value = "0.00" Then
                            'a = String.Format("{0:N2}", Double.Parse(a))
                            a = a + currentWorksheet.Cells(i, 35).Value
                            x1 = x1 + 1
                        End If
                        If currentWorksheet.Cells(i, 38).Value <> Nothing Or currentWorksheet.Cells(i, 38).Value = "0.00" Then
                            'b = String.Format("{0:N2}", Double.Parse(b))
                            b = b + currentWorksheet.Cells(i, 38).Value
                            x2 = x2 + 1
                        End If
                        If currentWorksheet.Cells(i, 41).Value <> Nothing Or currentWorksheet.Cells(i, 41).Value = "0.00" Then
                            'c = String.Format("{0:N2}", Double.Parse(c))
                            c = c + currentWorksheet.Cells(i, 41).Value
                            x3 = x3 + 1
                        End If
                    End If
                End If
                i = i + 1
            Loop
Do While currentWorksheet.Cells(i,1)。不设置任何值
如果workBook.Worksheets.Count>0,则
Name=currentWorksheet.Cells(i,1).Value
DataSo=当前工作表.单元格(i,33).值
尝试
Dim Conv As Double=Double.Parse(DataSo)
变量=DateTime.FromOADate(Conv.ToString(“MMMM/dd/yyyy”)
特例
结束尝试
Data1=Convert.ToDateTime(BOX\u Data1.Text)
Data2=Convert.ToDateTime(框_Data2.Text)
如果(currentWorksheet.Cells(i,4).Value)=“已完成”和(currentWorksheet.Cells(i,8).Value)=“RBT样本车间”,则

如果变量>=Data1且变量,则可以使用类似的代码:

Dim oledbConnectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
    & "DATA SOURCE=YourExcelFilePath.xls;" _
    & "EXTENDED PROPERTIES='Excel 8.0;HDR=No'"

Dim oledbConn As New OleDbConnection(oledbConnectionString)
oledbConn.Open()

Dim oledbCommand As OleDbCommand = oledbConn.CreateCommand()
oledbCommand.CommandText = "SELECT * " _
    & "FROM [YourExcelSheetName$] " _
    & "WHERE [F8] LIKE @filter + '%'"

oledbCommand.Parameters.Add("@filter", OleDbType.VarChar).Value = "sample shop"

Dim oledaXLSDaCaricare As New OleDbDataAdapter(oledbCommand)

Dim dtTest As New DataTable

Try
    oledaXLSDaCaricare.Fill(dtTest)
Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try

oledbConn.Close()
oledbConn.Dispose()
一些注意事项:

  • HDR=N
    o表示第一行不包含列名;也许您必须在
    HDR=Yes
  • [F8]
    是对工作表中第i列的引用,因此
    H

我不需要将我的值放在datatable中,我需要在筛选所有行之前读取所有值。