Dim xlApp As Object = Nothing
Dim xlBooks As Excel.Workbooks = Nothing
Dim xlBook As Excel.Workbook = Nothing
Dim xlSheets As Excel.Sheets = Nothing
Dim xlSheet As Excel.Worksheet = Nothing
Dim myrange As Excel.Range = Nothing
Dim i, j As Integer
Dim jshe, rows1 As Integer
Dim strFilePath As String = "C:\Users\Dell\Desktop\数据可视化测试\认统计2020.3.20.xlsx"
xlApp = New Excel.Application()
xlBooks = xlApp.Workbooks
xlBook = xlBooks.Open(strFilePath)
xlSheets = xlBook.Worksheets
xlSheet = xlSheets("Sheet1")
myrange = xlSheet.Range("h2")
MsgBox(xlSheet.UsedRange.Rows.Count)
TextBox1.Text = myrange.Text
For i = 2 To xlSheet.UsedRange.Rows.Count
If xlSheet.Range("h" & i).Value = Nothing Then
Exit For
End If
ListBox1.Items.Add(xlSheet.Range("h" & i).Value)
Next
For i = 0 To ListBox1.Items.Count - 1
For j = ListBox1.Items.Count - 1 To i + 1 Step -1
If ListBox1.Items(i) = ListBox1.Items(j) Then ListBox1.Items.RemoveAt(j)
Next
Next
rows1 = xlSheet.UsedRange.Rows.Count
jshe = xlSheets.Application.WorksheetFunction.SumIf(xlSheet.Range("h2:h" & rows1), ListBox1.Items.Item(0), xlSheet.Range("d2:d" & rows1))
TextBox1.Text = jshe
MsgBox(rows1)
xlBook.Close(True)
xlApp.Quit