我就是个小白,两列对比就和人工对比没区别,只是电脑速度快,点了核对后如下,代码随心所欲写的,不要在意变量的名称
[Visual Basic .NET] 纯文本查看 复制代码 Private Sub btn_hd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_hd.Click
Dim excel = Reo_excel.CurrentWorksheet
Dim max_row As Integer
Dim max_col As Integer = 3
max_row = excel.RowCount - 1
excel(0, 2) = "核对"
excel.SetRowsHeight(0, 1, 30) '设置行高
'excel.Cells(0, 2).Style.BackColor = Color.Green
For i = 1 To max_row
excel(i, 2) = "0"
Next
'开始核对,第一列和第二列开始对比
Dim I1, J1, H1 As String
For i = 1 To max_row
I1 = ""
If excel(i, 0) Is Nothing Then
excel(i, 0) = 0
End If
I1 = excel(i, 0).ToString
For j = 1 To max_row
J1 = ""
H1 = ""
If excel(j, 1) Is Nothing Then
excel(j, 1) = 0
End If
J1 = excel(j, 1).ToString
H1 = excel(j, 2).ToString
If I1 = J1 Then
If H1 = "0" Then
excel.Cells(i, 0).Style.BackColor = Color.Green
excel.Cells(j, 1).Style.BackColor = Color.Green
excel(j, 2) = i + 1 & "-->" & j + 1
Exit For
End If
End If
Next
Next
'整理核对后的数据
Dim num As Integer = 1
Dim c1, c2 As Color
For i = 1 To max_row
c1 = excel.Cells(i, 0).Style.BackColor
If c1.Name <> "ff008000" Then
excel(num, 5) = excel(i, 0).ToString
num += 1
End If
Next
num = 1
For i = 2 To max_row
c2 = excel.Cells(i, 1).Style.BackColor
If c2.Name <> "ff008000" Then
excel(num, 6) = excel(i, 1).ToString
num += 1
End If
Next
MessageBox.Show("双列数据已经核对完成!", "核对提醒", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
|