python-docx

使用python-docx来简单实现一个简历
具体如下

import os
import pymysql
from docx import Document


#定义函数后 需要调用  不然不会执行
def resumeCreate(**kwargs):
    #文件的扩展名
    fileExtension=".docx"
    name=kwargs['name']
    if name:   #python 如果name非空的话,逻辑值是真
        pass
    else:
        name="某某某"
    if os.path.exists(name+fileExtension):
        os.remove(name+fileExtension)
    document=Document()  #创建一个document,word文档
    document.add_heading("个人简历",0) #创建标题


    document.add_heading("个人基础信息",2)  #创建标题1
    #第一块内容

    name="xxx"#姓名
    sex="男"#性别
    age="20"#年龄
    nativeplace=kwargs["nativeplace"]#籍贯
    Major="大数据技术与应用"#专业
    telephone="***********"#电话
    document.add_paragraph("姓名:"+name+"性别:"+sex)
    document.add_paragraph("年龄:"+kwargs["age"]+"籍贯:"+nativeplace)
    document.add_paragraph("联系方式:"+telephone)

    document.add_heading("教育经历",2)
    educationExperice=kwargs["EducationExperice"]

    document.add_heading("所学课程",2)
    courses=kwargs["courses"]
    document.add_paragraph(courses)
    #第二块内容
    document.add_heading("学校经历",2)
    expericeList=kwargs["collegeExperice"]
    for experice in expericeList:
        document.add_paragraph(experice,style='List Number')
    #第三块内容
    document.add_heading("获得奖励",2)
    honorList=kwargs["honor"]
    for honor in honorList:
        document.add_paragraph(honor,style='List Number')
    document.add_heading("个人爱好",2)
    loveList=kwargs["love"]

    for love in loveList:
        document.add_paragraph(love)


    document.save(name+fileExtension)  #最后保存文档,提供文件名
if __name__=="__main__":  #,模块被单独执行的时候:__name__的值为__main__,

    #批量生成的话,数据来源一般是来自于数据库

    #从数据库里面读取数据(标准固定写法)
    conn=pymysql.connect(host="127.0.0.1",port=3306,user="root",
                                      passwd="zxl327",db="students",charset="utf8")
    cursor=conn.cursor(pymysql.cursors.DictCursor)

    sql="select * from stuinfo"
    cursor.execute(sql)
    rs=cursor.fetchall()
    for row in rs:    #从数据库里面获取的结果集,遍历处理,对每一条记录,调用一次函数
        name=row["stuName"]
        sex = row["stuSex"]
        age = row["stuAge"]
        nativeplace = row["stuNativePlace"]
        telphone = row["stuTelphone"]
        EducationExperice = row["stuEducationExperice"]
        collegeExperice = row["stuCollegeExperice"]
        collegeExperice=collegeExperice.split("|")  #使用|来判断是否需要分隔列表
        courses=row["stuCourses"]
        courses = courses.split("|")
        honor=row["stuHonor"]
        honor=honor.split("|")
        love = row["stuLove"]
        love = love.split("|")

        kw={"name":name,"sex":sex,"age":age,
            "nativeplace":nativeplace,"telphone":telphone,
            "EducationExperice":EducationExperice,"collegeExperice":collegeExperice,
            "courses":courses,"honor":honor,"love":love}
        resumeCreate(**kw)

mysql为了美观查看 这里使用Navicat for mysql进行查看
在这里插入图片描述
数据结构除主键外全部设置为varchar类型。

最后结果展示为
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值