本帖最后由 wankoilz 于 2015-11-21 22:40 编辑
将excel文件导出为csv文件,然后用以下批处理脚本处理,可以统计得到一个半成品
将文件图标拖拽到脚本上执行,看看效果:- # & cls & gawk -f %0 %1 & pause & exit
-
- BEGIN{
- FS=",| "
- check[1][1]=600;check[1][2]=730;check[1][3]=1110;check[1][4]=1230
- check[2][1]=1300;check[2][2]=1430;check[2][3]=1610;check[2][4]=1800
- check[3][1]=1830;check[3][2]=1910;check[3][3]=2100;check[3][4]=2200
- }
- {
- sub(/:/,"",$8)
- arr[$3" "$7]=arr[$3" "$7]""$8","
- }
- END{
- #将arr按姓名排序
- asorti(arr,ta)
- for(x in ta){
- gsub(","," ",arr[ta[x]])
- split(arr[ta[x]],arrTime," ")
- for(y in check){
- earlierFlag=0;laterFlag=0
- for(z in arrTime){
- if(arrTime[z]>=check[y][1]&&arrTime[z]<=check[y][2]){earlierFlag=1;earlierTime=arrTime[z]}
- if(arrTime[z]>=check[y][3]&&arrTime[z]<=check[y][4]){laterFlag=1;laterTime=arrTime[z]}
- }
- if(earlierFlag && laterFlag){
- sub(earlierTime,"",arr[ta[x]])
- sub(laterTime,"",arr[ta[x]])
- arr[ta[x]]=arr[ta[x]]" "earlierTime"-"laterTime
- }
- }
- }
- print "姓名,日期,开始时间,结束时间,标记" >>"result.csv"
- for(x in ta){
- split(arr[ta[x]],arrValue," ")
- for(y in arrValue){
- split(arrValue[y],arrTmp,"-")
- formatTime=""
- for(z in arrTmp){
- len=length(arrTmp[z])
- formatTime=formatTime","substr(arrTmp[z],1,len-2)":"substr(arrTmp[z],len-1,2)
- }
- if(length(formatTime)>6){formatTime=formatTime",1"}
- sub(" ",",",ta[x])
- print ta[x]""formatTime >>"result.csv"
- }
- }
- }
复制代码 gawk 4.1.0 下载地址:http://www.bathome.net/viewthread.php?tid=21366&highlight=gawk |