diff --git a/main.py b/main.py index eff5cc1..535ad46 100644 --- a/main.py +++ b/main.py @@ -127,10 +127,11 @@ def role_limit(role:str): logging.warning(f"职位[{role}]不存在职级上限规则") return -1 -def format_time(dt): +def format_time(dt,info): try: return dt.strftime("%Y.%m") except: + logging.warning(f"[{info}]时间格式错误:{dt}") return dt def to_int(x): @@ -161,10 +162,10 @@ def fill_basic_info(ws, row):# 填充基本信息 ws.cell(row=7, column=9, value=row["级别工资"]) ws.cell(row=7, column=10, value=row["职务工资金额"]) ws.cell(row=17, column=1, value=row["个人评价结果"]) - ws.cell(row=3, column=8, value=format_time(row["出生年月"])) - ws.cell(row=3, column=10, value=format_time(row["参加工作时间"])) - ws.cell(row=5, column=4, value=format_time(row["任职年月"])) - ws.cell(row=6, column=4, value=format_time(row["原职时间"])) + ws.cell(row=3, column=8, value=format_time(row["出生年月"],"出生年月")) + ws.cell(row=3, column=10, value=format_time(row["参加工作时间"],"参加工作时间")) + ws.cell(row=5, column=4, value=format_time(row["任职年月"],"任职年月")) + ws.cell(row=6, column=4, value=format_time(row["原职时间"],"原职时间")) def fill_prompt_info(ws, promote):# 填充晋升信息 for index, prow in promote.iterrows(): @@ -172,10 +173,7 @@ def fill_prompt_info(ws, promote):# 填充晋升信息 logging.warning(f"超过[{P_LIMIT}]条晋升信息,共[{promote.shape[0]}]条。") max_promote = max(max_promote, promote.shape[0]) break - try: - ws.cell(row=P_START+index, column=1, value=format_time(prow["任职时间"])) - except: - logging.warning(f"晋升时间格式错误:{prow['任职时间']}") + ws.cell(row=P_START+index, column=1, value=format_time(prow["任职时间"],"晋升时间")) ws.cell(row=P_START+index, column=2, value=prow["变动批注"]) ws.cell(row=P_START+index, column=3, value="任"+prow["新职务"]) @@ -184,7 +182,7 @@ def fill_history_info(ws, History_pd):# 填充历史记录 for col in range(1, 11): # 复制样式 ws.cell(row=H_START+index, column=col)._style = ws.cell(row=H_START, column=col)._style try: - ws.cell(row=H_START+index, column=1, value=hrow["时间"].strftime("%Y.%m")) + ws.cell(row=H_START+index, column=1, value=format_time(hrow["时间"],"历史时间")) except: logging.warning(f"历史时间格式错误:{hrow['时间']}") ws.cell(row=H_START+index, column=2, value=hrow["职务"]) @@ -291,17 +289,17 @@ for index, row in BaseData.iterrows(): # 汇总 ws.cell(row=6+index, column=1, value=index+1) ws.cell(row=6+index, column=2, value=row["姓名"]) ws.cell(row=6+index, column=3, value=row["性别"]) - ws.cell(row=6+index, column=4, value=format_time(row["出生年月"])) - ws.cell(row=6+index, column=5, value=format_time(row["参加工作时间"])) + ws.cell(row=6+index, column=4, value=format_time(row["出生年月"], "出生年月")) + ws.cell(row=6+index, column=5, value=format_time(row["参加工作时间"], "参加工作时间")) ws.cell(row=6+index, column=6, value=row["学历"]) - ws.cell(row=6+index, column=7, value=relativedelta(nowtime, row["入职时间"]).years+row["工龄调增"]-row["工龄调减"]+1) - ws.cell(row=6+index, column=8, value=relativedelta(nowtime, row["入职时间"]).years) + ws.cell(row=6+index, column=7, value=nowtime.year-row["入职时间"].year+row["工龄调增"]-row["工龄调减"]+1) + ws.cell(row=6+index, column=8, value=nowtime.year-row["入职时间"].year) ws.cell(row=6+index, column=9, value=row["工龄调增"]) ws.cell(row=6+index, column=10, value=row["工龄调减"]) ws.cell(row=6+index, column=11, value=row["Latest_Role"]) - ws.cell(row=6+index, column=12, value=format_time(row["Latest_Prom"])) + ws.cell(row=6+index, column=12, value=format_time(row["Latest_Prom"], "Latest_Prom")) ws.cell(row=6+index, column=13, value=row["职务2"]) - ws.cell(row=6+index, column=14, value=format_time(row["日期2"])) + ws.cell(row=6+index, column=14, value=format_time(row["日期2"], "日期2")) except Exception as e: logging.error(f"{row['身份证号码']}:{e}") wb.save("汇总名册.xlsx") # 保存汇总