当前位置:   article > 正文

人事工作中的Python运用——批量劳动合同+实习协议_python 提取合同信息

python 提取合同信息

HELLO,大家好呀!

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

合同内容要素主要是:

签订日期+合同金额+合同生效日期+合同结束日期+试用期结束日期+文件类型(劳动合同/实习协议)

准备一个EXCEL(命名为“批量合同.xlsx”),内容的填写要求见右边的提示

 劳动合同(命名为“劳动合同【模板勿动】.docx”)修改部分:

签订日期:

   奰         躄         罍   

合同期限:

本劳动合同为 √固定期限□无固定期限劳动合同,合同期限自日起至日止,共计年。其中试用期个月,自日起至日止。

合同工资:

 乙方每月工资为人民币  懿  元(税前)

  实习协议(命名为“实习协议【模板勿动】.docx”)修改部分:

实习合同期限:

第一条 本合同自  奰    躄    罍  日起生效, 颣    薐    豳  日终止。

 实习津贴:

第九条 如果甲乙双方就支付实习期间补贴的达成一致意见的,甲方以每月  懿  的标准支付乙方,并于次月15统一结算。

 签订日期:

 奰  日                     

以上合同内容请对应修改本公司自己的合同模板,切记一定要让替换的字符下面有下划线,否则会替换失败!

Python代码:

  1. from docx import Document
  2. from openpyxl import load_workbook
  3. import os
  4. import datetime
  5. import time
  6. # 结合路径判断生成文件夹,规避程序报错而终止的风险
  7. if not os.path.exists('./' + '全部合同'):
  8. os.mkdir('./' + '全部合同')
  9. print("创建目录成功")
  10. workbook = load_workbook( './' + '批量合同.xlsx')
  11. sheet = workbook.active
  12. #人数
  13. numbers = int(sheet.max_row)-1
  14. print("人数共计:{}人".format(str(numbers)))
  15. for table_row in range(2, sheet.max_row + 1):
  16. wordfile = Document('./' + '劳动合同【模板勿动】.docx')
  17. print("=====合同姓名类型=====")
  18. name = str(sheet.cell(row=table_row, column=1).value)
  19. print(name)
  20. series = str(sheet.cell(row=table_row, column=6).value)
  21. print(series)
  22. try:
  23. #获取合同开始日期
  24. print("=====合同开始日期=====")
  25. date_kaishi = sheet['B{}'.format(table_row)].value
  26. try:
  27. date_kaishi_year = "20"+str(date_kaishi.strftime('%y'))
  28. date_kaishi_month = str(date_kaishi.strftime('%m'))
  29. date_kaishi_day = str(date_kaishi.strftime('%d'))
  30. except:
  31. date_kaishi_year = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').year
  32. date_kaishi_month = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').month
  33. date_kaishi_day = datetime.datetime.strptime(date_kaishi,'%Y-%m-%d').day
  34. print(date_kaishi_year)
  35. print(date_kaishi_month)
  36. print(date_kaishi_day)
  37. #获取合同终止日期
  38. print("=====合同终止日期=====")
  39. date_zhongzhi = sheet['C{}'.format(table_row)].value
  40. try:
  41. date_zhongzhi_year = "20"+str(date_zhongzhi.strftime('%y'))
  42. date_zhongzhi_month = str(date_zhongzhi.strftime('%m'))
  43. date_zhongzhi_day = str(date_zhongzhi.strftime('%d'))
  44. except:
  45. date_zhongzhi_year = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').year
  46. date_zhongzhi_month = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').month
  47. date_zhongzhi_day = datetime.datetime.strptime(date_zhongzhi,'%Y-%m-%d').day
  48. print(date_zhongzhi_year)
  49. print(date_zhongzhi_month)
  50. print(date_zhongzhi_day)
  51. #获取合同试用日期
  52. print("=====试用截止日期=====")
  53. date_shiyong = sheet['D{}'.format(table_row)].value
  54. print(date_shiyong)
  55. if date_shiyong == None:
  56. print("无试用期")
  57. date_shiyong_if = "/"
  58. date_shiyong_year = "/"
  59. date_shiyong_month = "/"
  60. date_shiyong_day = "/"
  61. date_shiyong_year_1 = "/"
  62. date_shiyong_month_1 = "/"
  63. date_shiyong_day_1 = "/"
  64. else:
  65. date_shiyong_year = date_kaishi_year
  66. date_shiyong_month = date_kaishi_month
  67. date_shiyong_day = date_kaishi_day
  68. try:
  69. date_shiyong_if = "陆"
  70. date_shiyong_year_1 = "20"+str(date_shiyong.strftime('%y'))
  71. date_shiyong_month_1 = str(date_shiyong.strftime('%m'))
  72. date_shiyong_day_1 = str(date_shiyong.strftime('%d'))
  73. except:
  74. date_shiyong_if = "陆"
  75. date_shiyong_year_1 = datetime.datetime.strptime(date_shiyong,'%Y-%m-%d').year
  76. date_shiyong_month_1 = datetime.datetime.strptime(date_shiyong,'%Y-%m-%d').month
  77. date_shiyong_day_1 = datetime.datetime.strptime(date_shiyong,'%Y-%m-%d').day
  78. print(date_shiyong_if)
  79. print(date_shiyong_year)
  80. print(date_shiyong_month)
  81. print(date_shiyong_day)
  82. print(date_shiyong_year_1)
  83. print(date_shiyong_month_1)
  84. print(date_shiyong_day_1)
  85. #获取合同金额
  86. print("=====试用合同金额=====")
  87. money = sheet['E{}'.format(table_row)].value
  88. print(money)
  89. if series == "劳动合同":
  90. wordfile = Document('./' + '劳动合同【模板勿动】.docx')
  91. elif series == "实习协议":
  92. wordfile = Document('./' + '实习协议【模板勿动】.docx')
  93. else:
  94. print("暂时不支持本合同类型,跳过!")
  95. continue
  96. all_paragraphs = wordfile.paragraphs
  97. for paragraph in all_paragraphs:
  98. for run in paragraph.runs:
  99. try:
  100. if "奰" in run.text:
  101. run.text = run.text.replace("奰", date_kaishi_year)
  102. elif "躄" in run.text:
  103. run.text = run.text.replace("躄", date_kaishi_month)
  104. elif "罍" in run.text:
  105. run.text = run.text.replace("罍", date_kaishi_day)
  106. elif "颣" in run.text:
  107. run.text = run.text.replace("颣", date_zhongzhi_year)
  108. elif "薐" in run.text:
  109. run.text = run.text.replace("薐", date_zhongzhi_month)
  110. elif "豳" in run.text:
  111. run.text = run.text.replace("豳", date_zhongzhi_day)
  112. elif "懿" in run.text:
  113. run.text = run.text.replace("懿", str(money))
  114. elif "鰘" in run.text:
  115. run.text = run.text.replace("鰘", date_shiyong_if)
  116. elif "翳" in run.text:
  117. run.text = run.text.replace("翳", date_shiyong_year)
  118. elif "薹" in run.text:
  119. run.text = run.text.replace("薹", date_shiyong_month)
  120. elif "虩" in run.text:
  121. run.text = run.text.replace("虩", date_shiyong_day)
  122. elif "舄" in run.text:
  123. run.text = run.text.replace("舄", date_shiyong_year_1)
  124. elif "衚" in run.text:
  125. run.text = run.text.replace("衚", date_shiyong_month_1)
  126. elif "衕" in run.text:
  127. run.text = run.text.replace("衕", date_shiyong_day_1)
  128. except Exception as e:
  129. print("替换文本出错:"+str(e))
  130. except Exception as e:
  131. print("出错:"+str(e))
  132. wordfile.save('./' + f'全部合同/{name}_{series}.docx')
  133. print(f"{name}_{series}.docx | 另存成功")
  134. input ("Please Enter to close this exe:")

测试:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/741334
推荐阅读
相关标签
  

闽ICP备14008679号