博客
关于我
python自动化办公 word操作
阅读量:77 次
发布时间:2019-02-25

本文共 2823 字,大约阅读时间需要 9 分钟。

Python-docx ???????Word ?????????

??????

? Windows ?????? Python 3.8 ???????? Python ?????

D:\Python\Python38\Scripts> pip3.8 install python-docx

?????????? python -m docx ???????

??????????

add_paragraph() ??????????????? Paragraph ??????????

  • add_run()?????????????????
  • clear()?????????????
  • insert_paragraph_before()????????????
  • alignment??????????
  • paragraph_format????????
  • style?????????????
  • text??????????

????????

????
from docx import Documentdocument = Document()

?????

document.add_heading("??????", level=0)document.add_heading("??????", level=1)document.add_heading("??????", level=2)

?????

document.add_picture("????.png", width=Inches(1), height=Inches(1))

?????

document.add_paragraph("?????")document.add_page_break()document.add_paragraph("?????")

?????

document.add_table(rows=3, cols=3)

???????

paragraph = document.add_paragraph("?????????????\n?????????????\n")paragraph.add_run("????????????\n????????????\n")prior_paragraph = paragraph.insert_paragraph_before("?????")
????
document.save("0-????.docx")

???????????

from docx import Documentimport osfrom docx.shared import Inchesdef generate_resume(filename, profile, basic, education, experience, personal, photo_path):    document = Document()    document.add_heading("????:", level=1)    document.add_paragraph(profile)        document.add_heading("????:", level=1)    document.add_paragraph(basic)    document.add_picture(photo_path, width=Inches(1), height=Inches(1))        document.add_heading("????:", level=1)    document.add_paragraph(education)        document.add_heading("????:", level=1)    document.add_paragraph(experience)        document.add_heading("????:", level=1)    document.add_paragraph(personal)        document.save(f"{filename}.docx")    return
??????
import osfrom docx import Documentdef jianli(filename, yixiang, basic, edcate, experience, personal, photo):    document = Document()    document.add_heading("????:", level=1)    document.add_paragraph(yixiang)        document.add_heading("????:", level=1)    document.add_paragraph(basic)    document.add_picture(photo, width=Inches(1), height=Inches(1))        document.add_heading("????:", level=1)    document.add_paragraph(edcate)        document.add_heading("????:", level=1)    document.add_paragraph(experience)        document.add_heading("????:", level=1)    document.add_paragraph(personal)        document.save(f"{filename}.docx")    return# ??????os.mkdir("????")os.chdir("????")for i in range(1, 1000):    jianli(str(i),            "??",            f"{i}??\t"+"123456"+"123456@qq.com",           f"xx??",           f"????",           f"?????????",           "../???.png")    print(f"? {i} ??????\n")

??????

  • ??????????????????????????????
  • ???????????????????????????
  • ???????????????????????????
  • ??????????????????????????
  • ????????????? Word ???????????????????

    转载地址:http://rfv.baihongyu.com/

    你可能感兴趣的文章
    Objective-C实现单向链表的反转(附完整源码)
    查看>>
    Objective-C实现单字母密码算法(附完整源码)
    查看>>
    Objective-C实现单尺度SSR算法(附完整源码)
    查看>>
    Objective-C实现单循环链表算法(附完整源码)
    查看>>
    Objective-C实现单板密码算法(附完整源码)
    查看>>
    Objective-C实现单词计数(附完整源码)
    查看>>
    Objective-C实现单链表(附完整源码)
    查看>>
    Objective-C实现单链表反转(附完整源码)
    查看>>
    Objective-C实现博福特密码算法(附完整源码)
    查看>>
    Objective-C实现卡尔曼滤波(附完整源码)
    查看>>
    Objective-C实现卡尔曼滤波(附完整源码)
    查看>>
    Objective-C实现卡尔曼滤波(附完整源码)
    查看>>
    Objective-C实现卡恩拓扑algorithm topo算法(附完整源码)
    查看>>
    Objective-C实现卷积(附完整源码)
    查看>>
    Objective-C实现卷积神经网络CNN(附完整源码)
    查看>>
    Objective-C实现卷积运算(附完整源码)
    查看>>
    Objective-C实现卷积运算(附完整源码)
    查看>>
    Objective-C实现压缩字符串(附完整源码)
    查看>>
    Objective-C实现压缩文件夹(附完整源码)
    查看>>
    Objective-C实现原型模式(附完整源码)
    查看>>