Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog dlg.Filter= "Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb" '设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim kqsj As Date = Functions.Execute("自定义时间",8,30,0) '定义正常上班时间8:30 Dim kqsj2 As Date = Functions.Execute("自定义时间",10,30,0) '定义上午考勤最后有效时间10:30 Dim kqsj3 As Date = Functions.Execute("自定义时间",11,0,0) '定义上午缺席时间11:00 Dim kqsj4 As Date = Functions.Execute("自定义时间",14,30,0) '定义下午上班时间14:30 Dim kqsj5 As Date = Functions.Execute("自定义时间",15,30,0) '定义下午考勤最后有效时间8:30 Dim kqsj12 As Date = Functions.Execute("自定义时间",12,00,0) ''定义考勤时间12:00 '注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 For n As Integer = 4 To 10 Step 2 Output.Show(Sheet(n,2).Value) Output.Show(Sheet(n,10).Value) Dim p As String = Sheet(n+1,1).Value Dim r As Row = Tables("表A").addnew r("工号")=Sheet(n,2).Value r("姓名") =Sheet(n,10).Value Dim zd As New Dictionary(Of Integer,String) For Each s As String In p.Replace(vbcr,"").Split(vblf) Dim s1 As Date If Date.TryParse(s, s1) Then messagebox.Show(s1) r("考勤时间") = r("考勤时间") & s1 '----判断是否按时上班(8:30以前)------ If s1 < kqsj Then If zd.ContainsValue("上午正常") = False Then zd.Add(1,"上午正常") r("sw")=zd(1) End If End If '-----'----判断是否迟到(8:30至10:30)------ If s1 > kqsj And s1 < kqsj2 Then If zd.ContainsValue("上午正常") = False Then If zd.ContainsValue("上午迟到") = False Then zd.Add(2,"上午迟到") End If r("sw")=zd(2) End If End If '------------判断是否缺席(晚于11:00或缺席)------ If s1 > kqsj3 Then If zd.ContainsValue("上午正常") = False AndAlso zd.ContainsValue("上午迟到") = False Then If zd.ContainsValue("上午缺席") = False Then zd.Add(3,"上午缺席") End If r("sw")=zd(3) End If End If '------------判断下午是否正常上班(早于14:30或缺席)------ If s1 > kqsj12 And s1< kqsj4 Then If zd.ContainsValue("下午正常") = False zd.Add(4,"下午正常") r("xw")=zd(4) End If End If '------------判断下午是否迟到(14:30-15:30)------ If s1 > kqsj4 And s1< kqsj5 Then If zd.ContainsValue("下午正常") = False If zd.ContainsValue("下午迟到") = False Then zd.Add(5,"下午迟到") End If r("xw")=zd(5) End If End If '------------判断下午是否缺席 (晚于15:30)------ If s1 >= kqsj5 Then If zd.ContainsValue("下午正常") = False AndAlso zd.ContainsValue("下午迟到") = False Then If zd.ContainsValue("下午缺席") = False Then zd.Add(6,"下午缺席") End If r("xw")=zd(6) End If End If End If Next zd.Clear Next End If
|