该excel表有如下结构

姓名\日期 周1 周2 周3  周4 周5
张三     7:35
18:02
7:35
18:02
7:46   17:56
李四 7:35
18:02

7:02

18:00

18:02

     

需要判断每天是否迟到早退,并生成考勤表

用如下自定义函数cal或者cals

Public Function cal(ByVal cs As Range) As Integer

'计算单元格并返回相应值如下
'没打卡 1
'正常上下班 0
'迟到 2
'迟到超过2小时 11
'早退 3
'早退超过2小时 12
'迟到+早退 5
'迟到+早退分别都超过2小时
'只有上班打卡,没有下班打卡 4
'只有上班打卡,迟到,没下班打卡 2+4=6
'只有下班打卡,没有上班打卡 7
'只有下班打卡,早退,没有上班打卡 3+7=10
'一天3次打卡记录30
'一天n次以上(n>3)打卡记录 N*10=10n
'异常打卡 10:00-15:30打卡 8
Const morning_time = "08:00"
Const evening_time = "17:30"
'超过120分钟算旷工
Const offset_point = '单元格每行是一个数组元素lines()
Dim lines() As String
'单元格有多少行
Dim count As Integer '没打卡-空值,返回1 相当于count=0
If IsEmpty(cs) Then
cal =
Exit Function
End If count = Len(cs.Text) - Len(Application.WorksheetFunction.Substitute(cs.Text, Chr(), "")) + '大于3次以上的打卡记录返回10*n
If count >= Then
cal = count *
Exit Function
End If '处理只有一条记录的,并计算是否上班
If count = Then Dim offset_morning, offset_evening As Integer offset_morning = Hour(CDate(cs.Text) - CDate(morning_time)) * + Minute(CDate(cs.Text) - CDate(morning_time))
offset_evening = Hour(CDate(cs.Text) - CDate(evening_time)) * + Minute(CDate(cs.Text) - CDate(evening_time))
'MsgBox offset_morning
If CDate(cs.Text) <= CDate(morning_time) Then
' 只有上班打卡,没有下班打卡
cal =
'MsgBox cal
Exit Function End If If CDate(cs.Text) >= CDate(evening_time) Then
' 只有下班打卡,没有上班班打卡
cal =
Exit Function
End If If (CDate(cs.Text) > CDate(morning_time)) And (CDate(cs.Text) < CDate(evening_time)) Then
If offset_morning < Then
'只有上班打卡,迟到,没有下班打卡
cal =
ElseIf offset_evening < Then
'只有下班打卡,早退,没有上班打卡
cal =
Else
'异常打卡
cal =
End If Exit Function
End If 'count=1
End If 'count=2
Dim line1, line2 As String
Dim moring_tmp, evening_tmp As Integer
morning_tmp =
evening_tmp =
'提取第一行打卡和第二行打卡时间line1是上班打卡,line2是下班打卡
line1 = Left(cs.Text, )
line2 = Split(cs.Text, Chr())()
'MsgBox "line1:" & line1
'MsgBox "line2:" & line2 '分别给出 morning_tmp值:如果line1早于8点则返回0,晚于8点且不超过2小时为迟到2,超过2小时取值11 offset_morning = Hour(CDate(line1) - CDate(morning_time)) * + Minute(CDate(line1) - CDate(morning_time))
offset_evening = Hour(CDate(line2) - CDate(evening_time)) * + Minute(CDate(line2) - CDate(evening_time)) 'MsgBox offset_morning
'MsgBox offset_evening If CDate(line1) <= CDate(morning_time) Then
' 正常上班打卡早于8点
morning_tmp =
ElseIf (CDate(line1) > CDate(morning_time)) And (offset_morning < ) Then
' 上班迟到
morning_tmp =
Else
' 上班迟到超过2小时
morning_tmp = End If '分别给出 evening_tmp值:如果line2晚于于17:30则返回0,早于17:30且不超过2小时为早退取值3,超过2小时给值12, If CDate(line2) >= CDate(evening_time) Then
' 正常下班打卡
evening_tmp =
ElseIf (CDate(line2) < CDate(evening_time)) And (offset_evening < ) Then
' 早退
evening_tmp =
Else
' 早退超过2小时
evening_tmp = End If '最终cal= morning_tmp+evening_tmp
cal = morning_tmp + evening_tmp End Function Public Function cals(ByVal cs As Range) As String '计算单元格并返回相应值如下
'没打卡 1
'正常上下班 0
'迟到 2
'迟到超过2小时 11
'早退 3
'早退超过2小时 12
'迟到+早退 5
'迟到+早退分别都超过2小时
'只有上班打卡,没有下班打卡 4
'只有上班打卡,迟到,没下班打卡 2+4=6
'只有下班打卡,没有上班打卡 7
'只有下班打卡,早退,没有上班打卡 3+7=10
'一天3次打卡记录30
'一天n次以上(n>3)打卡记录 N*10=10n
'异常打卡 10:00-15:30打卡 8
Const morning_time = "08:00"
Const evening_time = "17:30"
'超过120分钟算旷工
Const offset_point = '单元格每行是一个数组元素lines()
Dim lines() As String
'单元格有多少行
Dim count As Integer '没打卡-空值,返回1 相当于count=0
If IsEmpty(cs) Then
cals = "休息"
Exit Function
End If count = Len(cs.Text) - Len(Application.WorksheetFunction.Substitute(cs.Text, Chr(), "")) + '大于3次以上的打卡记录返回10*n
If count >= Then
cals = "异常打卡" & CStr(count) & "次"
Exit Function
End If '处理只有一条记录的,并计算是否上班
If count = Then Dim offset_morning, offset_evening As Integer offset_morning = Hour(CDate(cs.Text) - CDate(morning_time)) * + Minute(CDate(cs.Text) - CDate(morning_time))
offset_evening = Hour(CDate(cs.Text) - CDate(evening_time)) * + Minute(CDate(cs.Text) - CDate(evening_time))
'MsgBox offset_morning
If CDate(cs.Text) <= CDate(morning_time) Then
' 只有上班打卡,没有下班打卡
cals = "无下班打卡"
'MsgBox cal
Exit Function End If If CDate(cs.Text) >= CDate(evening_time) Then
' 只有下班打卡,没有上班班打卡
cals = "无上班打卡"
Exit Function
End If If (CDate(cs.Text) > CDate(morning_time)) And (CDate(cs.Text) < CDate(evening_time)) Then
If offset_morning < Then
'只有上班打卡,迟到,没有下班打卡
cals = "迟到,无下班打卡"
ElseIf offset_evening < Then
'只有下班打卡,早退,没有上班打卡
cals = "早退,无上班打卡"
Else
'异常打卡
cals = "10点15点30之间异常打卡"
End If Exit Function
End If 'count=1
End If 'count=2
Dim line1, line2 As String
Dim moring_tmp, evening_tmp As Integer
morning_tmp =
evening_tmp =
'提取第一行打卡和第二行打卡时间line1是上班打卡,line2是下班打卡
line1 = Left(cs.Text, )
line2 = Split(cs.Text, Chr())()
'MsgBox "line1:" & line1
'MsgBox "line2:" & line2 '分别给出 morning_tmp值:如果line1早于8点则返回0,晚于8点且不超过2小时为迟到2,超过2小时取值11 offset_morning = Hour(CDate(line1) - CDate(morning_time)) * + Minute(CDate(line1) - CDate(morning_time))
offset_evening = Hour(CDate(line2) - CDate(evening_time)) * + Minute(CDate(line2) - CDate(evening_time)) 'MsgBox offset_morning
'MsgBox offset_evening If CDate(line1) <= CDate(morning_time) Then
' 正常上班打卡早于8点
morning_tmp =
ElseIf (CDate(line1) > CDate(morning_time)) And (offset_morning < ) Then
' 上班迟到
morning_tmp =
Else
' 上班迟到超过2小时
morning_tmp = End If '分别给出 evening_tmp值:如果line2晚于于17:30则返回0,早于17:30且不超过2小时为早退取值3,超过2小时给值12, If CDate(line2) >= CDate(evening_time) Then
' 正常下班打卡
evening_tmp =
ElseIf (CDate(line2) < CDate(evening_time)) And (offset_evening < ) Then
' 早退
evening_tmp =
Else
' 早退超过2小时
evening_tmp = End If '最终cal= morning_tmp+evening_tmp 'MsgBox morning_tmp + evening_tmp
Select Case (morning_tmp + evening_tmp) Case
cals = "全勤"
Case
cals = "休息"
Case
cals = "迟到"
Case
cals = "早退"
Case
cals = "无下班打卡"
Case
cals = "迟到+早退"
Case
cals = "上班迟到,下班没打卡"
Case
cals = "无上班打卡"
Case
cals = "10:00-15:30异常打卡"
Case
cals = "早退,无上班打卡"
Case
cals = "迟到超2小时"
Case
cals = "早退超2小时"
Case
cals = "迟到早退都超2小时"
Case Else
calse = "异常打卡" & CStr(morning_tmp + evening_tmp) & "次" End Select End Function

Public Function cal(ByVal cs As Range) As Integer
'计算单元格并返回相应值如下'没打卡 1'正常上下班 0'迟到 2'迟到超过2小时 11'早退 3'早退超过2小时 12'迟到+早退 5'迟到+早退分别都超过2小时'只有上班打卡,没有下班打卡 4'只有上班打卡,迟到,没下班打卡 2+4=6'只有下班打卡,没有上班打卡 7'只有下班打卡,早退,没有上班打卡 3+7=10'一天3次打卡记录30'一天n次以上(n>3)打卡记录 N*10=10n'异常打卡 10:00-15:30打卡 8Const morning_time = "08:00"Const evening_time = "17:30"'超过120分钟算旷工Const offset_point = 120
'单元格每行是一个数组元素lines()Dim lines() As String'单元格有多少行Dim count As Integer

'没打卡-空值,返回1 相当于count=0If IsEmpty(cs) Then    cal = 1    Exit FunctionEnd If

count = Len(cs.Text) - Len(Application.WorksheetFunction.Substitute(cs.Text, Chr(10), "")) + 1
'大于3次以上的打卡记录返回10*nIf count >= 3 Then    cal = count * 10    Exit FunctionEnd If

'处理只有一条记录的,并计算是否上班If count = 1 Then
Dim offset_morning, offset_evening As Integer
offset_morning = Hour(CDate(cs.Text) - CDate(morning_time)) * 60 + Minute(CDate(cs.Text) - CDate(morning_time))offset_evening = Hour(CDate(cs.Text) - CDate(evening_time)) * 60 + Minute(CDate(cs.Text) - CDate(evening_time))'MsgBox offset_morning   If CDate(cs.Text) <= CDate(morning_time) Then   ' 只有上班打卡,没有下班打卡      cal = 4      'MsgBox cal      Exit Function         End If         If CDate(cs.Text) >= CDate(evening_time) Then   ' 只有下班打卡,没有上班班打卡      cal = 7      Exit Function   End If         If (CDate(cs.Text) > CDate(morning_time)) And (CDate(cs.Text) < CDate(evening_time)) Then      If offset_morning < 120 Then          '只有上班打卡,迟到,没有下班打卡          cal = 6      ElseIf offset_evening < 120 Then        '只有下班打卡,早退,没有上班打卡            cal = 10       Else        '异常打卡            cal = 8      End If                Exit Function    End If   'count=1End If
'count=2Dim line1, line2 As StringDim moring_tmp, evening_tmp As Integermorning_tmp = 0evening_tmp = 0'提取第一行打卡和第二行打卡时间line1是上班打卡,line2是下班打卡line1 = Left(cs.Text, 5)line2 = Split(cs.Text, Chr(10))(1)'MsgBox "line1:" & line1'MsgBox "line2:" & line2
'分别给出 morning_tmp值:如果line1早于8点则返回0,晚于8点且不超过2小时为迟到2,超过2小时取值11

offset_morning = Hour(CDate(line1) - CDate(morning_time)) * 60 + Minute(CDate(line1) - CDate(morning_time))offset_evening = Hour(CDate(line2) - CDate(evening_time)) * 60 + Minute(CDate(line2) - CDate(evening_time))
'MsgBox offset_morning'MsgBox offset_evening
If CDate(line1) <= CDate(morning_time) Then   ' 正常上班打卡早于8点        morning_tmp = 0      ElseIf (CDate(line1) > CDate(morning_time)) And (offset_morning < 120) Then      ' 上班迟到        morning_tmp = 2      Else      ' 上班迟到超过2小时        morning_tmp = 11               End If

'分别给出 evening_tmp值:如果line2晚于于17:30则返回0,早于17:30且不超过2小时为早退取值3,超过2小时给值12,
If CDate(line2) >= CDate(evening_time) Then   ' 正常下班打卡        evening_tmp = 0      ElseIf (CDate(line2) < CDate(evening_time)) And (offset_evening < 120) Then      ' 早退        evening_tmp = 3      Else      ' 早退超过2小时        evening_tmp = 12               End If
'最终cal= morning_tmp+evening_tmpcal = morning_tmp + evening_tmp

End Function

Public Function cals(ByVal cs As Range) As String
'计算单元格并返回相应值如下'没打卡 1'正常上下班 0'迟到 2'迟到超过2小时 11'早退 3'早退超过2小时 12'迟到+早退 5'迟到+早退分别都超过2小时'只有上班打卡,没有下班打卡 4'只有上班打卡,迟到,没下班打卡 2+4=6'只有下班打卡,没有上班打卡 7'只有下班打卡,早退,没有上班打卡 3+7=10'一天3次打卡记录30'一天n次以上(n>3)打卡记录 N*10=10n'异常打卡 10:00-15:30打卡 8Const morning_time = "08:00"Const evening_time = "17:30"'超过120分钟算旷工Const offset_point = 120
'单元格每行是一个数组元素lines()Dim lines() As String'单元格有多少行Dim count As Integer

'没打卡-空值,返回1 相当于count=0If IsEmpty(cs) Then    cals = "休息"    Exit FunctionEnd If

count = Len(cs.Text) - Len(Application.WorksheetFunction.Substitute(cs.Text, Chr(10), "")) + 1
'大于3次以上的打卡记录返回10*nIf count >= 3 Then    cals = "异常打卡" & CStr(count) & "次"    Exit FunctionEnd If

'处理只有一条记录的,并计算是否上班If count = 1 Then
Dim offset_morning, offset_evening As Integer
offset_morning = Hour(CDate(cs.Text) - CDate(morning_time)) * 60 + Minute(CDate(cs.Text) - CDate(morning_time))offset_evening = Hour(CDate(cs.Text) - CDate(evening_time)) * 60 + Minute(CDate(cs.Text) - CDate(evening_time))'MsgBox offset_morning   If CDate(cs.Text) <= CDate(morning_time) Then   ' 只有上班打卡,没有下班打卡      cals = "无下班打卡"      'MsgBox cal      Exit Function         End If         If CDate(cs.Text) >= CDate(evening_time) Then   ' 只有下班打卡,没有上班班打卡      cals = "无上班打卡"      Exit Function   End If         If (CDate(cs.Text) > CDate(morning_time)) And (CDate(cs.Text) < CDate(evening_time)) Then      If offset_morning < 120 Then          '只有上班打卡,迟到,没有下班打卡          cals = "迟到,无下班打卡"      ElseIf offset_evening < 120 Then        '只有下班打卡,早退,没有上班打卡            cals = "早退,无上班打卡"       Else        '异常打卡            cals = "10点15点30之间异常打卡"      End If                Exit Function    End If   'count=1End If
'count=2Dim line1, line2 As StringDim moring_tmp, evening_tmp As Integermorning_tmp = 0evening_tmp = 0'提取第一行打卡和第二行打卡时间line1是上班打卡,line2是下班打卡line1 = Left(cs.Text, 5)line2 = Split(cs.Text, Chr(10))(1)'MsgBox "line1:" & line1'MsgBox "line2:" & line2
'分别给出 morning_tmp值:如果line1早于8点则返回0,晚于8点且不超过2小时为迟到2,超过2小时取值11

offset_morning = Hour(CDate(line1) - CDate(morning_time)) * 60 + Minute(CDate(line1) - CDate(morning_time))offset_evening = Hour(CDate(line2) - CDate(evening_time)) * 60 + Minute(CDate(line2) - CDate(evening_time))
'MsgBox offset_morning'MsgBox offset_evening
If CDate(line1) <= CDate(morning_time) Then   ' 正常上班打卡早于8点        morning_tmp = 0      ElseIf (CDate(line1) > CDate(morning_time)) And (offset_morning < 120) Then      ' 上班迟到        morning_tmp = 2      Else      ' 上班迟到超过2小时        morning_tmp = 11               End If

'分别给出 evening_tmp值:如果line2晚于于17:30则返回0,早于17:30且不超过2小时为早退取值3,超过2小时给值12,
If CDate(line2) >= CDate(evening_time) Then   ' 正常下班打卡        evening_tmp = 0      ElseIf (CDate(line2) < CDate(evening_time)) And (offset_evening < 120) Then      ' 早退        evening_tmp = 3      Else      ' 早退超过2小时        evening_tmp = 12               End If
'最终cal= morning_tmp+evening_tmp
'MsgBox morning_tmp + evening_tmpSelect Case (morning_tmp + evening_tmp)

Case 0cals = "全勤"Case 1 cals = "休息"Case 2   cals = "迟到"Case 3   cals = "早退"Case 4    cals = "无下班打卡"Case 5     cals = "迟到+早退"Case 6    cals = "上班迟到,下班没打卡"Case 7    cals = "无上班打卡"Case 8    cals = "10:00-15:30异常打卡"Case 10    cals = "早退,无上班打卡"Case 11    cals = "迟到超2小时"Case 12     cals = "早退超2小时"Case 23    cals = "迟到早退都超2小时"Case Else    calse = "异常打卡" & CStr(morning_tmp + evening_tmp) & "次"

End Select

End Function

考勤打卡机导出的excel考勤时间表如何生成实用的考勤表的更多相关文章

  1. Magic xpa 3.x很容易将数据导出到Excel中

    Magic xpa 3.x很方便的将表中数据导出到Excel文件中,还可以自动将表中数据生成各种图表. 通过使用自带的打印数据内部事即可实现. 1.首先将打印数据任务属性设置为“是”. 2.可使用主程 ...

  2. 将ACCESS 的数据库中的表的文件 导出了EXCEL格式

    将ACCESS 的数据库中的表的文件 导出了EXCEL格式 '''' '将ACCESS数据库中的某个表的信息 导出为EXCEL 文件格式 'srcfName ACCESS 数据库文件路径 'desfN ...

  3. DataTable导出到Excel

    简单的导出到Excel中: 代码如下: using System; using System.Collections.Generic; using System.Data; using System. ...

  4. ASP.NET中GridView数据导出到Excel

    /// <summary> /// 导出按钮 /// </summary> /// <param name="sender"></para ...

  5. 【Java EE 学习 17 下】【数据库导出到Excel】【多条件查询方法】

    一.导出到Excel 1.使用DatabaseMetaData分析数据库的数据结构和相关信息. (1)测试得到所有数据库名: private static DataSource ds=DataSour ...

  6. PB的datawindow导出到excel文件(使用saveasascii)

    **********************************************************//*函数名称:uf_dwsaveas_excel功能:将数据窗口数据导出EXCEL ...

  7. 纯JS 将table表格导出到excel

    html <div > <button type="button" onclick="getXlsFromTbl('tableExcel','myDiv ...

  8. 将页面上的内容导出到Excel

    <asp:Button ID="lkbExport" runat="server" Name="Save" Text="导出 ...

  9. asp.net教程:GridView导出到Excel或Word文件

    asp.net教程:GridView导出到Excel或Word文件</ br> 在项目中我们经常会遇到要求将一些数据导出成Excel或者Word表格的情况,比如中国移动(我是中国移动用户) ...

随机推荐

  1. Hadoop的伪分布式的安装

    查看下载地址:http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.4.0-src.tar.gz 解压hadoop-2.6.0-cdh5.4 ...

  2. [加密]非对称加密STM32实现

    转自:https://blog.csdn.net/kangerdong/article/details/82432701 把所有的准备工作都做完了以后,可以将加密算法移植到我们具体的项目中去了,在ST ...

  3. linux设备驱动程序--hello-world

    linux字符设备驱动程序--hello_world 基于4.14内核, beagleBone green平台 PC端的设备驱动程序 有过电脑使用经验的人都知道,当我们将外部硬件设备比如鼠标键盘插入到 ...

  4. SQL注入(2)

    SQL注入id  title  content  time  author select * from news where id = 1; select 1,2,3,4,5,6 from table ...

  5. git提交时报错处理办法

    git提交时报错:Updates were rejected because the tip of your current branch is behind: 有如下几种解决方法: 1.使用强制pu ...

  6. python案例-判断素数

    from math import sqrt def is_prime(num): for rea in range(2,int(sqrt(num)+1)): if num%rea==0: return ...

  7. crontab每小时运行一次(转)

    https://blog.csdn.net/liu0808/article/details/80668705 先给出crontab的语法格式 对于网上很多给出的每小时定时任务写法,可以说绝大多数都是错 ...

  8. nginx 获取源IP 获取经过N层Nginx转发的访问来源真实IP

    1. nginx 配置文件中获取源IP的配置项 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; #一般的we ...

  9. CSS进阶之路

    下面主要引用http://www.cnblogs.com/wangfupeng1988/tag/css知多少/ CSS进阶笔记: 一.学习CSS的三个突破点 1.浏览器如何加载和解析CSS——CSS的 ...

  10. 客户端本地存储,web存储,localStorage

    HTML5 LocalStorage 本地存储 说到本地存储,这玩意真是历尽千辛万苦才走到HTML5这一步,之前的历史大概如下图所示: 最早的Cookies自然是大家都知道,问题主要就是太小,大概也就 ...