下面这段代码能实现去重复,但是如果数组中列名称的顺序和Excel表中的列顺序不一致会错误,请问一下 列名称的顺序和Excel表中的列顺序不一致的情况下代码该怎么修改?
Dim Book As New XLS.Book(dlg.filename)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("计时临时考勤表").StopRedraw()
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"工号","部门名称","姓名","正常出勤","平常加班","假日加班","合计考勤","考勤扣款","满勤天数","合计调休天数","高温补贴"}
Dim i As Integer =0
Dim k As Integer=0
For n As Integer = 1 To Sheet.Rows.Count -1
Dim gh As String = sheet(n,0).Text 'excel文件第3列
If DataTables("计时临时考勤表").Find("工号 = '" & gh & "' ") Is Nothing Then '如果不存在同编号的订单
Dim r As Row = Tables("计时临时考勤表").AddNew()
For m As Integer = 0 To nms.Length - 1
r(nms(m)) = Sheet(n,m).Value
r("日期") = _xzyf
Next
i=i+1 '记录导入条数
Else
For Each r As Row In Tables("计时工资_table1").Rows
If r("工号") =gh Then
r.Checked = True
End If
Next
End If
Next
MessageBox.Show("共有" & Sheet.Rows.Count -1 &"条记录,成功导入" & i & "记录 ,重复记录为" & Sheet.Rows.Count -1 -i & "条" )
Tables("计时临时考勤表").ResumeRedraw()