我使用包含90000行的excel文件,通过应用某个过滤器(" MANUFACTURING DEPARTMENT")我可以将其减少到2000.
为了加快文件读取速度,我想在读取文件之前应用该过滤器。
我试过这个
Dim myRange As Excel.Range
myRange = currentWorksheet.SelectedRange("A1", "L2")
myRange.Select()
myRange.Sort(Key1:=myRange.Range("H1"), _
DataOption1:=("SAMPLE SHOP"), _
Order1:=Excel.XlSortOrder.xlAscending)
但是得到那个错误:
Conversion from string "A1" to type 'Integer' is not valid.
我希望过滤" SAMPLE SHOP"
我的代码是:
If workBook.Worksheets.Count > 0 Then
Dim lastRow As Long = Nothing
Dim currentWorksheet As ExcelWorksheet = workBook.Worksheets.First()
Dim SOname As String = Nothing
Dim Name As String = Nothing
Dim TimeCompletyDefinited As Decimal = Nothing
'lastRow = currentWorksheet.Cells(lastRow, "A").End(xlUp).Row
Dim i As Long = 1
Dim a As Double = 0
Dim b As Double = 0
Dim c As Double = 0
Dim myRange As Excel.Range
myRange = currentWorksheet.SelectedRange("A1", "L2")
myRange.Select()
myRange.Sort(Key1:=myRange.Range("H1"), _
DataOption1:=("SAMPLE SHOP"), _
Order1:=Excel.XlSortOrder.xlAscending)
Do While currentWorksheet.Cells(i, 1).Value <> Nothing
Name = currentWorksheet.Cells(i, 1).Value
Try
TimeCompletyDefinited = currentWorksheet.Cells(i, 36).Value
Catch ex As Exception
End Try
If (currentWorksheet.Cells(i, 4).Value) = "Completed" And (currentWorksheet.Cells(i, 8).Value) = "RBT SAMPLE SHOP" Then
a = a + currentWorksheet.Cells(i, 35).Value
b = b + currentWorksheet.Cells(i, 36).Value
c = c + currentWorksheet.Cells(i, 38).Value
End If
i = i + 1
Loop
end if