该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. Pandas 之 Series / DataFrame 初识

    import numpy as np import pandas as pd Pandas will be a major tool of interest throughout(贯穿) much o ...

  2. IDEA创建本地Spark程序,并本地运行

    1   IDEA创建maven项目进行测试 v创建一个新项目,步骤如下: 选择“Enable Auto-Import”,加载完后:选择“Enable Auto-Import”,加载完后: 添加SDK依 ...

  3. mac php Swoole入门

    一. swoole 扩展安装 安装前必须保证系统已经安装了下列软件 php-7.0 或更高版本 gcc-4.8 或更高版本 make autoconf pcre (CentOS系统可以执行命令:yum ...

  4. 学习Spring5源码时所遇到的坑

    学习Spring5源码时所遇到的坑 0)本人下载的源码版本是 spring-framework-5.0.2.RELEASE 配置好gradle环境变量之后,cmd进入到spring项目,执行gradl ...

  5. Mac安装vscode IDE 撸nodejs代码

    1. vscode官网地址:https://code.visualstudio.com   找到mac对应的下载地址,下载后的文件是 zip压缩包,解压后将文件拖到Application目录下即可. ...

  6. Linux 环境变量配置错误,导致所有命令找不到

    今天配置环境变量,PATH设置出错,所有的命令都找不到了,提示说在/usr/bin/下面可以找到,但是cd过去以后还是不行,自己也在其他路径上找了,还是没找到 而且是公司开发机,怕耽误事儿,着实吓了一 ...

  7. Linux创建目录和文件的默认权限设置

    这两天,项目中使用jenkins自动构建系统时遇到了在Linux中创建目录和文件的权限问题,临时的解决办法是在脚本中增加了chmod赋权限命令; 偶然想到Linux应该是可以设置默认权限的,故学习了一 ...

  8. Vuex之辅助函数

    mapState.mapGetters.mapActions 如果我们不喜欢这种在页面上使用“this.$stroe.state.count”和“this.$store.dispatch('funNa ...

  9. es6 Object 数据属性和访问器属性

    原文 :http://www.jb51.net/article/91698.htm 总结 ES5提供了Object.getOwnPropertyDescripter()方法来获取给定属性的描述符. p ...

  10. 17-Flutter移动电商实战-首页_楼层区域的编写

    1.楼层标题组件 该组件非常简单,只接收一个图片地址,然后显示即可: class FloorTitle extends StatelessWidget {  final String picture_ ...