人力资源管理工作的其他Python运用

人事工作中的Python运用——批量劳动合同+实习协议_派圣的博客-CSDN博客

相信大家工作中,会时常有员工向我们所要离职证明或者实习协议,遇见我们人事工作手头很紧,忙不过来,那么自动生成神奇你值得拥有,其实逻辑跟上面那个文章差不多,大家看一下就懂了,就可以发挥各种想象去开发了!

脚本逻辑:

1.我们公司会有自己制作的花名册excel,里面有很多sheet,有个“离职”sheet

2.请确认列数对应与脚本一致,不一致修改即可

准备模板文件(命名:“离职证明【模板勿动】.docx”),请务必替换字符要带下划线;

XXX有限公司

离职证明

兹有 ,身份证号码为 ,于 与我司签订劳动合同,离职时工作岗位为

经协商一致,我司同意该员工于 日解除劳动合同。

特此证明。

本人签字:

XXX有限公司

                                                   

代码一(无UI):

from docx import Document
from openpyxl import load_workbook
import os
import datetime
import time
# 结合路径判断生成文件夹,规避程序报错而终止的风险
if not os.path.exists('./' + '离职证明导出'):os.mkdir('./' + '离职证明导出')print("创建目录成功")
import tkinter as tk
from tkinter import filedialog
print("请选择花名册文件")
try:root = tk.Tk()root.withdraw()Filepath = filedialog.askopenfilename()workbook = load_workbook(Filepath)
except:print("未选择文件,请重新选择!")root = tk.Tk()root.withdraw()Filepath = filedialog.askopenfilename()workbook = load_workbook(Filepath)
sheet = workbook["离职"]
numbers = int(sheet.max_row)-1
who = input("请输入姓名:")
summit = 0
for table_row in range(2, sheet.max_row + 1):name = str(sheet.cell(row=table_row, column=6).value)if name == who:print("找到1个符合条件")try:try:print("=====入职日期=====")date_kaishi =  sheet['I{}'.format(table_row)].valuetry:date_kaishi_year = "20"+str(date_kaishi.strftime('%y')) date_kaishi_month = str(date_kaishi.strftime('%m'))date_kaishi_day = str(date_kaishi.strftime('%d'))except:date_kaishi_year = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').yeardate_kaishi_month = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').monthdate_kaishi_day = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').dayprint(date_kaishi_year)print(date_kaishi_month)print(date_kaishi_day)print("=====离职日期=====")date_zhongzhi = sheet['J{}'.format(table_row)].valuetry:date_zhongzhi_year = "20"+str(date_zhongzhi.strftime('%y')) date_zhongzhi_month = str(date_zhongzhi.strftime('%m'))date_zhongzhi_day = str(date_zhongzhi.strftime('%d'))except:date_zhongzhi_year = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').yeardate_zhongzhi_month = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').monthdate_zhongzhi_day = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').dayprint(date_zhongzhi_year)print(date_zhongzhi_month)print(date_zhongzhi_day)print("=====身份证=====")date_ID = sheet['H{}'.format(table_row)].valueprint(date_ID)print("=====岗位=====")GW = sheet['E{}'.format(table_row)].valueprint(GW)wordfile = Document('./' + '离职证明【模板勿动】.docx')all_paragraphs = wordfile.paragraphsfor paragraph in all_paragraphs:for run in paragraph.runs:try:if "奰" in run.text:run.text = run.text.replace("奰", date_kaishi_year)elif "躄" in run.text:  run.text = run.text.replace("躄", date_kaishi_month)elif "罍" in run.text:  run.text = run.text.replace("罍", date_kaishi_day)elif "颣" in run.text:  run.text = run.text.replace("颣", date_zhongzhi_year)elif "薐" in run.text:   run.text = run.text.replace("薐", date_zhongzhi_month)elif "豳" in run.text:run.text = run.text.replace("豳", date_zhongzhi_day)elif "懿" in run.text:run.text = run.text.replace("懿", str(date_ID))elif "鰘" in run.text:run.text = run.text.replace("鰘", str(GW))    elif "礥" in run.text:run.text = run.text.replace("礥", str(who))    except Exception as e:print("替换文本出错:"+str(e)) wordfile.save('./' + f'离职证明导出/{table_row}_{name}_离职证明.docx')print(f"{table_row}_{name}_离职证明.docx | 另存成功")summit += 1except Exception as e:print("内出错:"+str(e)) except Exception as e:print("外出错:"+str(e))
if summit == 0:print(f"未查到 {who}!!!!!\n")
elif summit == 1:print("导出一份,结束!\n")
elif summit >= 2:print("结束!\n")print(f"本次共导出 {summit} 个 {who}的离职文件,请注意筛选!!!!!\n")
input ("Please Enter to close this exe:")

代码一(有UI,用的wxpython框架):

# -*- coding: utf-8 -*-
import wx
import time
import tkinter as tk
from tkinter import filedialogfrom docx import Document
from openpyxl import load_workbook
import os
import datetimedef lzzm(Filepath,who):if not os.path.exists('./' + '离职证明导出'):os.mkdir('./' + '离职证明导出')contents.AppendText("创建目录成功\n")workbook = load_workbook(Filepath)sheet = workbook["离职"]summit = 0for table_row in range(2, sheet.max_row + 1):name = str(sheet.cell(row=table_row, column=6).value)if name == who:contents.AppendText("查到一个符合条件\n")try:try:contents.AppendText("=====入职日期=====\n")date_kaishi =  sheet['I{}'.format(table_row)].valuetry:date_kaishi_year = "20"+str(date_kaishi.strftime('%y')) date_kaishi_month = str(date_kaishi.strftime('%m'))date_kaishi_day = str(date_kaishi.strftime('%d'))except:date_kaishi_year = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').yeardate_kaishi_month = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').monthdate_kaishi_day = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').daycontents.AppendText(date_kaishi_year)contents.AppendText(date_kaishi_month)contents.AppendText(date_kaishi_day+"\n")contents.AppendText("=====离职日期=====\n")date_zhongzhi = sheet['J{}'.format(table_row)].valuetry:date_zhongzhi_year = "20"+str(date_zhongzhi.strftime('%y')) date_zhongzhi_month = str(date_zhongzhi.strftime('%m'))date_zhongzhi_day = str(date_zhongzhi.strftime('%d'))except:date_zhongzhi_year = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').yeardate_zhongzhi_month = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').monthdate_zhongzhi_day = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').daycontents.AppendText(date_zhongzhi_year)contents.AppendText(date_zhongzhi_month)contents.AppendText(date_zhongzhi_day+"\n")contents.AppendText("=====身份证=====\n")   date_ID = sheet['H{}'.format(table_row)].valuecontents.AppendText(str(date_ID)+"\n")contents.AppendText("=====岗位=====\n") GW = sheet['E{}'.format(table_row)].valuecontents.AppendText(str(GW)+"\n")contents.AppendText("即将生成文件...\n") wordfile = Document('./' + '离职证明【模板勿动】.docx')all_paragraphs = wordfile.paragraphsfor paragraph in all_paragraphs:for run in paragraph.runs:try:if "奰" in run.text:run.text = run.text.replace("奰", date_kaishi_year)elif "躄" in run.text:  run.text = run.text.replace("躄", date_kaishi_month)elif "罍" in run.text:  run.text = run.text.replace("罍", date_kaishi_day)elif "颣" in run.text:  run.text = run.text.replace("颣", date_zhongzhi_year)elif "薐" in run.text:   run.text = run.text.replace("薐", date_zhongzhi_month)elif "豳" in run.text:run.text = run.text.replace("豳", date_zhongzhi_day)elif "懿" in run.text:run.text = run.text.replace("懿", str(date_ID))elif "鰘" in run.text:run.text = run.text.replace("鰘", str(GW))    elif "礥" in run.text:run.text = run.text.replace("礥", str(who))    except Exception as e:print("替换文本出错:"+str(e)) wordfile.save('./' + f'离职证明导出/{table_row}_{name}_离职证明.docx')contents.AppendText(f"{table_row}_{name}_离职证明.docx | 另存成功\n")summit += 1except Exception as e:contents.AppendText("内出错:"+str(e)+"\n") except Exception as e:contents.AppendText("外出错:"+str(e)+"\n") if summit == 0:contents.AppendText(f"未查到 {who}!!!!!\n")elif summit == 1:contents.AppendText("导出一份,结束!\n")elif summit >= 2:contents.AppendText("结束!\n")contents.AppendText(f"本次共导出 {summit} 个 {who}的离职文件,请注意筛选!!!!!\n")def choice(event):print("请选择文件")root = tk.Tk()root.withdraw()Filepath = filedialog.askopenfilename() #获得选择好的文件print('Filepath:',Filepath)filename.SetValue(Filepath)def Go(event):if filename.GetValue() == "" or filename.GetValue() == "未选择文件":contents.AppendText("未选择文件,请选择后运行\n")elif filename1.GetValue() == "请输入姓名" or filename1.GetValue() == "":contents.AppendText("未输入姓名,请输入后运行\n")else:try:lzzm(Filepath=filename.GetValue(),who=filename1.GetValue())except Exception as e:contents.AppendText(f"{e}:运行失败!\n")app = wx.App()
win = wx.Frame(None,title = "离职证明快速生成小助手", size=(535,520))
bkg = wx.Panel(win)
#设置icon
##icon = wx.Icon(r'logo.ico')
##win.SetIcon(icon)
#设置透明度
win.SetTransparent(230)
loadButton = wx.Button(bkg, label = '选择文件')
loadButton.Bind(wx.EVT_BUTTON,choice)
saveButton = wx.Button(bkg, label = '开始运行')
saveButton.Bind(wx.EVT_BUTTON,Go)
filename = wx.TextCtrl(bkg,value = "未选择文件", style = wx.TE_READONLY)
filename1 = wx.TextCtrl(bkg,value = "请输入姓名")
contents = wx.TextCtrl(bkg,value = "程序指南:\n1.选择文件选择花名册后\n2.请输入需要制作离职证明的姓名\n3.点击开始运行,如果在离职的sheet里面存在此人会导出,反之不存在!\n ====================\n", style = wx.TE_MULTILINE | wx.HSCROLL | wx.TE_READONLY)
hbox = wx.BoxSizer()
hbox.Add(filename, proportion =1, flag = wx.EXPAND)
hbox.Add(loadButton, proportion =0,flag = wx.LEFT, border = 5)
pbox = wx.BoxSizer()
pbox.Add(filename1, proportion =1, flag = wx.EXPAND)
pbox.Add(saveButton, proportion =0,flag = wx.LEFT, border = 5)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(hbox,proportion = 0,flag = wx.EXPAND | wx.ALL, border = 5)
vbox.Add(pbox,proportion = 0,flag = wx.EXPAND | wx.ALL, border = 5)
vbox.Add(contents, proportion = 1,flag=wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, border = 5)
bkg.SetSizer(vbox)
win.Show()
app.MainLoop()

测试:

人事工作中的Python运用——离职证明生成器相关推荐

  1. 人事工作中的Python运用——批量劳动合同+实习协议

    HELLO,大家好呀! 今天为大家带来的是"python批量劳动合同+实习协议生成器",为什么我会制作这个程序,因为我所在的实习公司人流量流动很大,所以一人一份的准备手动打合同就非 ...

  2. python在日常工作处理中的应用-近期工作中应用Python的一些经验总结

    本文由Markdown语法编辑器编辑完成. 1. Python 在来新公司前,也间断地接触过Python编程,比如医学影像处理的图像库VTK就已经有Python的实现:Paraview也可以开启Pyt ...

  3. python contains类似函数_01--实际工作中,python基础理念和数据处理

    1.工作中遇到的python坑 1.1 合并文件 问题:正常将文件依次读取并append时,莫名出现很多空行. 解决:在append前删除空行: data_tmp 1.2 重复数据行 问题: appe ...

  4. python课堂随机点名_【工作中的Python】随机点名小脚本

    背景:项目组每周的例会中,有一项固定内容就是技术分享,可以是与工作相关或无关的任何技术主题.进行技术分享讲解的同学是随机抽签的.由此做了一个Python的小脚本用于抽取姓名. 脚本内容如下: #!/u ...

  5. 软件测试用python一般用来做什么-如何将Python应用到实际测试工作中?

    基础问题(学员的问题) 学员问题第一类"Python的应用" (1)如何将Python运用到实际测试工作中,Python自动化能做哪些方面的自动化 (2)怎么利用python进行自 ...

  6. 离职证明(解除劳动合同书)是否会毁你一生?

    只要你不是有编制的事业单位.公职人员,那么离职证明对你来说不会有致命性影响,更不可能让你有所谓的毁一生.但要说一点影响都没有,那是不可能的! 离职证明的作用有这些 想有编制的事业单位.公职人员.以及部 ...

  7. 【芝麻背调百科】HR们小心,一张离职证明,有可能让企业损失惨重!

    案例概述 王某是某公司的员工,入职一年后,他向公司提交<辞职报告>,要求辞职. 公司答复:因王某任职期间部分贷款未能收回等原因,不批准他的辞职.于是王某申请协商与仲裁,要求公司支付因公司未 ...

  8. 领导最懂怎么恶心人!离职一个多月才拿到离职证明,领导竟在上面留下自己电话用来背调!...

    领导能有多恶心人? 一位人事主管晒出了自己离职证明,上面竟然有一行手写的公司背调电话号码! 楼主说,领导非常喜欢在背后说别人坏话. 网友问,为什么要在离职证明上加背调电话?太奇葩了吧. 楼主回答:为了 ...

  9. 没有离职证明能入职吗(离职证明丢了能入职吗)

    离职证明丢了是不影响入职的,用人单位获取离职证明是因为<劳动法>第九十九条规定:用人单位招用尚未解除劳动合同的劳动者,对原用人单位造成经济损失的,该用人单位应当依法承担连带赔偿责任.这也引 ...

最新文章

  1. 2022-2028年中国木制拼板玩具市场调查研究报告
  2. 《Cortex-M0权威指南》之体系结构---异常和中断
  3. java同步锁synchronized_Java对象锁和类锁全面解析(多线程synchronized关键字)
  4. Soul网关发布2.1.X之后,它到底有多方便?
  5. [leetcode] 141.环形链表
  6. 临汾移动搜索引擎推广_竞价信息流移动搜索推广分析!
  7. Android实现mp3分析,Android编程实现播放MP3功能示例
  8. 戴尔计算机windows未能启动,戴尔电脑windows7无法启动安装过程怎么办
  9. 微信第三方登陆,无需注册一键登录,获取用户信息,PHP实现方法
  10. linux基础命令学习笔记(二)
  11. k8s自定义指标HPA实践(微服务基于自定义指标自动扩缩容的实践)附demo
  12. 干货:Java并发编程系列之volatile(二)
  13. 从源码分析HashSet集合
  14. html原生js请求
  15. 遥感数字图像处理复习(朱文泉)
  16. GoEasy使用方法记录
  17. 浅谈西门子840d主轴速度控制_西门子 840D 数控系统故障诊断与维修
  18. 威金又现!专杀收集整合
  19. 395. Longest Substring with At Least K Repeating Characters 1
  20. vue transition淡入淡出

热门文章

  1. png图片怎么压缩大小又不损失画质?
  2. 用layui创建表格
  3. python四大数据类型——python筑基系列
  4. Context R-CNN一种基于注意力机制的视频检测算法
  5. 蓝桥杯 算法训练 一元三次方程求解
  6. PHP学习案例9 双色球
  7. 产品设计工具-摩客和墨刀
  8. Python 输入、输出
  9. linux wall命令_如何在Linux上使用wall命令
  10. php怎么转mp4,php使用memcoder将视频转成mp4格式的方法