python: 读取EXCEL的请假数据
https://www.oreilly.com/library/view/programming-python-4th/9781449398712/
https://www.oreilly.com/library/view/learning-python-5th/9781449355722/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | # encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2023/9/2 21:31 # User : geovindu # Product : PyCharm # Project : LukfookLeaveCalculation # File : Holiday.py # explain : 学习 class Holiday( object ): """ 假期实体类 """ def __init__( self ): self .hName = "" self .hId = 0 self .workTime = 0 @property def HolidayId( self ): """ 假期ID 获取 :return: """ return self .hId @HolidayId .setter def HolidayId( self ,hId: int ): """ 假期ID 设置 :param hId: :return: """ self .hId = hId @property def HolidayName( self ): """ 假期名称 :return: """ return self .hName @HolidayName .setter def HolidayName( self ,hName): """ 假期名称 :param hName: :return: """ self .hName = hName @property def WorkTime( self ): """ 工作/请假/休假时间(小时制) :return: """ return self .workTime @WorkTime .setter def WorkTime( self ,workTime): """ 工作/请假/休假时间(小时制) :param workTime: :return: """ self .workTime = workTime # encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2023/9/2 20:20 # User : geovindu # Product : PyCharm # Project : LukfookLeaveCalculation # File : Employee.py # explain : 学习 import sys import os class employee( object ): """ 职员实体类 """ def __init__( self ): self .empId = 0 self .empNO = "" self .empName = "" self .empDep = "" self .empHolidays = [] self .activeDate = "" @property def EmployeeId( self ): """ ID :return: """ return self .empId @EmployeeId .setter def EmployeeId( self ,empId): """ id :param empId: :return: """ self .empId = empId @property def EmployeeNo( self ): """ 工号 :return: """ return self .empNO @EmployeeNo .setter def EmployeeNo( self ,empNo): """ 工号 :param empNo: :return: """ self .empNO = empNo @property def EmployeeDep( self ): """ :return: """ return self .empDep; @EmployeeDep .setter def EmployeeDep( self ,empDep): """ :param empDep: :return: """ self .empDep = empDep @property def EmployeeName( self ): """ 姓名 :return: """ return self .empName @EmployeeName .setter def EmployeeName( self ,empName): """ 姓名 :param empName: :return: """ self .empName = empName @property def EmployeeHolidays( self ): """ 假期 :return: """ return self .empHolidays @EmployeeHolidays .setter def EmployeeHolidays( self ,empHolidays) - > list : """ 假期 :param empHolidays: :return: """ self .empHolidays = empHolidays @property def EmployeeActiveDate( self ): """ 发生时间 :return: """ return self .activeDate @EmployeeActiveDate .setter def EmployeeActiveDate( self ,activeDate): """ 发生时间 :param activeDate: :return: """ self .activeDate = activeDate # encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2023/9/3 7:04 # User : geovindu # Product : PyCharm # Project : LukfookLeaveCalculation # File : EmpLoyeeHolidaysGet.py # explain : 学习 import sys import os import Common.Utils import Model.Holiday class EmpLoyeeHolidaysGet( object ): """ 抽取需要的数据 """ def getYear( self ,strsource): """ :param strsource: :return: """ refloat = 0 if (strsource ! = None ): if ( "年" in strsource): refloat = Common.Utils.Utils.getYear(strsource) return refloat def getMonth( self , strsource): """ :param strsource: :return: """ refloat = 0 if (strsource ! = None ): if ( "月" in strsource): refloat = Common.Utils.Utils.getMonth(strsource) return refloat def getDay( self , strsource): """ :param strsource: :return: """ refloat = 0 if (strsource ! = None ): if ( "日" in strsource): refloat = Common.Utils.Utils.getDay(strsource) return refloat def getHolidays( self ,strsource): """ 獲得假期限列表 :param strsource: :return: """ hday = [] if (strsource ! = None ): if ( "星期" not in strsource): if ( "nan" not in strsource): spstr = strsource.split( ' ' ) # 有两个,有换行符,两个假期,一定要这换行符 NaN if ( len (spstr) > 1 ): for i in range ( len (spstr)): sk = spstr[i] #print("for sk", sk) hd = Model.Holiday.Holiday() hd = EmpLoyeeHolidaysGet.checkHoliday( self ,sk) hday.append(hd) elif ( len (spstr) = = 1 ): sk = spstr[ 0 ] #print("sk",sk) hd = Model.Holiday.Holiday() hd = EmpLoyeeHolidaysGet.checkHoliday( self ,sk) hday.append(hd) else : hday = [] else : hday = [] return hday def checkHoliday( self ,strsource): """ 检测是什么假期 :param strsource: :return: """ hd = Model.Holiday.Holiday() print ( "chek" ) if ( "例休" in strsource): #print("cehck例休") hd.HolidayId = 1 hd.HolidayName = "例休" hd.WorkTime = Common.Utils.Utils.getRegularHoliday(strsource) if ( "特假" in strsource): hd.HolidayId = 2 hd.HolidayName = "特假" hd.workTime = Common.Utils.Utils.getSpecialLeave(strsource) if ( "補休" in strsource): hd.HolidayId = 3 hd.HolidayName = "補休" hd.workTime = Common.Utils.Utils.getDeferredHoliday(strsource) if ( "加班" in strsource): hd.HolidayId = 4 hd.HolidayName = "加班" hd.workTime = Common.Utils.Utils.getOvertime(strsource) if ( "事假" in strsource): hd.HolidayId = 5 hd.HolidayName = "事假" hd.workTime = Common.Utils.Utils.getPersonalLeave(strsource) if ( "年假" in strsource): hd.HolidayId = 6 hd.HolidayName = "年假" hd.workTime = Common.Utils.Utils.getAnnualLeave(strsource) if ( "病假" in strsource): hd.HolidayId = 7 hd.HolidayName = "病假" hd.workTime = Common.Utils.Utils.getSickLeave(strsource) if ( "育兒假" in strsource): hd.HolidayId = 8 hd.HolidayName = "育兒假" hd.workTime = Common.Utils.Utils.getChildcareLeave(strsource) if ( "遲到" in strsource): hd.HolidayId = 9 hd.HolidayName = "遲到" hd.workTime = Common.Utils.Utils.getLateTime(strsource) return hd # This is a sample Python script. # encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2023/9/2 20:20 # User : geovindu # Product : PyCharm # Project : LukfookLeaveCalculation # File : main.py # explain : 学习 # Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. import xlrd import xlwt import xlwings as xw import xlsxwriter import openpyxl as openws import pandas as pd import numpy as np import pandasql import os import sys import Common.Utils import BLL.EmpLoyeeHolidaysGet import Model.Employee def print_hi(name): # Use a breakpoint in the code line below to debug your script. print (f 'Hi, {name}' ) # Press Ctrl+F8 to toggle the breakpoint. # Press the green button in the gutter to run the script. if __name__ = = '__main__' : print_hi( 'PyCharm' ) unstr = Common.Utils.Utils() strtest = "年假2小時 事假0.5小時" # 换行符 #strtest-strtest.replace('_x000D_', ' ', regex=True) #strtest = "NaN" spstr = strtest.split( " " ) thbll = BLL.EmpLoyeeHolidaysGet.EmpLoyeeHolidaysGet() tt = thbll.getHolidays(spstr[ 0 ]) print ( "tt" ,tt[ 0 ].WorkTime,spstr) dataframe1 = pd.read_excel( '2023年7月.xlsx' ) #print(dataframe1) #for idx, data in dataframe1.iterrows(): #print("[{}]: {}".format(idx, data)) # 第1列为日期,其他列是员工对应的列的考勤 print ( "*************" ) print (dataframe1.index) print ( "*************" ) print (dataframe1.shape) #行列 datarowcol = dataframe1.shape print ( "行:" ,datarowcol[ 0 ], ",列:" ,datarowcol[ 1 ]) excelRows = datarowcol[ 0 ] excelColumns = datarowcol[ 1 ] print ( "*********列标题****" ) print (dataframe1.columns) #第一行标题 pandas.core.indexes.base.Index titls = dataframe1.columns.to_list() print (titls) print ( "标题:" ,titls[ 1 ]) year = thbll.getYear(titls[ 1 ]) print ( "*************" ,year) dmps = [] # 姓名,工号,序号,部门 0行至3行为员工资料 第一行为标题,不算行的内容 可以切片方式GET数据 #序号 idlist = [] dataId = dataframe1.loc[ 0 : 0 ] for idx, datadd in dataId.iterrows(): print ( "[{}]: {}" . format (idx, datadd)) idlist = datadd.to_list() for idd in range ( 1 , len (idlist)): #employvee=Model.Employee.employee() #employvee.EmployeeId=idd #dmps.append(employvee) print (idd) print ( "*******序号******" ) #工号 nolist = [] dataNo = dataframe1.loc[ 1 : 1 ] for idx, dataoo in dataNo.iterrows(): print ( "[{}]: {}" . format (idx, dataoo)) nolist = dataoo.to_list() print ( "*******工号******" ) #部门 deplist = [] dataDep = dataframe1.loc[ 2 : 2 ] for idx, datapp in dataDep.iterrows(): print ( "[{}]: {}" . format (idx, datapp)) deplist = datapp.to_list() print ( "*******部门******" ) #姓名 namelist = [] dataName = dataframe1.loc[ 3 : 3 ] for idx, datann in dataName.iterrows(): print ( "[{}]: {}" . format (idx, datann)) namelist = datann.to_list() print ( "*******姓名******" ) for i in range ( 1 , len (namelist)): employvee = Model.Employee.employee() employvee.EmployeeId = idlist[i] employvee.EmployeeNo = nolist[i] employvee.EmployeeName = namelist[i] employvee.EmployeeDep = deplist[i] dmps.append(employvee) for ob in dmps: print (ob.EmployeeId,ob.EmployeeNo,ob.EmployeeName,ob.EmployeeDep) #data1 = dataframe1.loc[0:3] #print(type(data1)) #print(data1) #for idx, data in data1.iterrows(): #print("[{}]: {}".format(idx, data)) #print("*************") AnnualLeave = 0 Overtime = 0 DeferredHoliday = 0 SpecialLeave = 0 PersonalLeave = 0 SickLeave = 0 ChildcareLeave = 0 LateTime = 0 # 内容 readrows = (excelRows - 1 ) - 3 #索此值从零开始,所以总数减一,再减三行统计的 data4 = dataframe1.loc[ 4 :readrows] #第四行开始内空 for idx, datavalue in data4.iterrows(): #strnum=Common.Utils.Utils.getAnnualLeave(data) print ( "[{}]: {}" . format (idx, datavalue)) slist = datavalue.tolist() hbll = BLL.EmpLoyeeHolidaysGet.EmpLoyeeHolidaysGet() #病假4小時_x000D_事假0.5小時 未处理 #print(slist) for i in range ( 0 , 1 ): strvalue = str (slist[i]) print ( "get value:" , strvalue.replace( 'nan' , ''), type (strvalue)) mon = hbll.getMonth(strvalue) day = hbll.getDay(strvalue) print ( "*******时间************" ,mon,day) for i in range ( 1 , len (slist)): #strvalue=str(slist[i]).replace(r'\s+|\\n', ' ', regex=True) _x000D_ #isnan=np.isnan(slist[i]) #if(isnan): strvalue = str (slist[i]).replace( '_x000D_' , ' ' ) # 规换单元格的换行符,否则处理不了正确数据 #strvalue = str(slist[i]).replace('nan', ' ') print ( "get value:" ,strvalue.replace( 'nan' ,''), type (strvalue)) strnums = hbll.getHolidays(strvalue) # float str if ( len (strnums)> 0 ): for sn in range ( len (strnums)): print ( "str:" ,strnums[sn].HolidayId,strnums[sn].HolidayName,strnums[sn].WorkTime) if strnums[sn].HolidayId = = 6 : AnnualLeave = AnnualLeave + strnums[sn].WorkTime if strnums[sn].HolidayId = = 4 : Overtime = Overtime + strnums[sn].WorkTime if strnums[sn].HolidayId = = 3 : DeferredHoliday = DeferredHoliday + strnums[sn].WorkTime if strnums[sn].HolidayId = = 2 : SpecialLeave = SpecialLeave + strnums[sn].WorkTime if strnums[sn].HolidayId = = 5 : PersonalLeave = PersonalLeave + strnums[sn].WorkTime if strnums[sn].HolidayId = = 7 : SickLeave = SickLeave + strnums[sn].WorkTime if strnums[sn].HolidayId = = 8 : ChildcareLeave = ChildcareLeave + strnums[sn].WorkTime if strnums[sn].HolidayId = = 9 : LateTime = LateTime + strnums[sn].WorkTime else : print ( "0" ) print ( "类型:" , type (datavalue)) print ( "*************" ) print ( "年假合计:" ,AnnualLeave, "加班合计:" ,Overtime, "补休合计:" ,DeferredHoliday, "特假合计:" ,SpecialLeave) print ( "事假合计" ,PersonalLeave, "病假合计:" ,SickLeave, "迟到合计:" ,LateTime, "育儿假合计:" ,ChildcareLeave) print ( "*************" ) dataframe2 = openws.load_workbook( "2023年7月.xlsx" ) # Define variable to read sheet dataframe2 = dataframe2.active # Iterate the loop to read the cell values #for row in range(0, dataframe2.max_row): #for col in dataframe2.iter_cols(1, dataframe2.max_column): #print(col[row].value) # a single cell #v1 = xw.range("A1:A7").value #v2 = xw.range("F5").value #print("Result:", v1) # See PyCharm help at https://www.jetbrains.com/help/pycharm/ |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2013-09-06 Csharp: Send Email
2012-09-06 Csharp Datatable sort