博客
关于我
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/

    你可能感兴趣的文章
    Python selenium爬取影评生成词云图
    查看>>
    python selenium自动化测试报告
    查看>>
    Python selenium自动化测试框架实战 —— 登录测试案例
    查看>>
    Python Selenium设计模式 —— POM
    查看>>
    Python Serial:如何使用 read 或 readline 函数一次读取多个字符
    查看>>
    Python set([]) 如何检查两个对象是否相等?一个对象需要定义哪些方法来自定义它?
    查看>>
    Python setup.py:数据文件无法复制目录:不存在或不是常规文件
    查看>>
    Python setuptools sdist:仅安装版本化文件
    查看>>
    Python Shell下使用matplotlib
    查看>>
    Python Slice How-to,我知道Python Slice,但我怎么才能使用内置的Slice对象呢?
    查看>>
    python socket分包发送数据
    查看>>
    python socket模块_Python socket模块实现TCP服务端客户端
    查看>>
    Python SOCKS5代理客户端HTTPS
    查看>>
    Python Soc网络分析:通过使用函数迭代列表来计算机会网络
    查看>>
    python转换已转义的字符串
    查看>>
    Python Sphinx自动摘要:成员函数的自动列表
    查看>>
    Python SQL和NoSQL数据库操作实战
    查看>>
    python stdout flush_sys.stdout.flush()方法的用法
    查看>>
    python string 运算
    查看>>
    Python str与bytes之间的转换
    查看>>