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

    你可能感兴趣的文章
    php-有序数组合并后仍有序
    查看>>
    redis使用
    查看>>
    Redis以及Redis的php扩展安装
    查看>>
    PHP-算法-最少比较次数获取最大值最小值
    查看>>
    php-约瑟夫问题
    查看>>
    Redis从库不能同步报Can’t save in background: fork: Cannot allocate memory错误
    查看>>
    Redis从入门到精通|干货篇
    查看>>
    php.ini maxfileuploads,细说PHP高洛峰文件上传类源文件
    查看>>
    php.ini中常见的配置信息选项
    查看>>
    php.ini配置中有10处设置不当,会使网站存在安全问题
    查看>>
    php/jsp/asp的区别
    查看>>
    php20个主流框架
    查看>>
    php301到https,虚拟主机设置自动301跳转到HTTPS
    查看>>
    php5 apache 配置
    查看>>
    php5 升级 php7 版本遇到的问题处理方法总结
    查看>>
    PHP5.3.3安装Mcrypt扩展
    查看>>
    PHP5.4 + IIS + Win2008 R2 配置
    查看>>
    PHP5.4 pfsocketopen函数判断sock是否存活的bug(由memcached引起)
    查看>>
    Redis从入门到精通
    查看>>
    PHP5.6.x编译报错:Don't know how to define struct flock on this system, set --enable-opcache=no
    查看>>