欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python-docx批量生成word文档方法1

程序员文章站 2022-04-18 18:48:08
...

批量生成word文档办法1
python-docx 0.8.7 documentation

pip install python-docx
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = "leo"
__time__ = "2018-10-30"

from docx import Document
from docx.shared import Pt

if __name__ == '__main__':

    for i in range(1, 151):
        input_doc = Document('INNOVATIONS 正嘜-CHINA.docx')
        c = '  C/NO. %d C\n  MADE IN CHINA' % i
        run = input_doc.add_paragraph('').add_run(c)
        run.bold = True
        font = run.font
        font.name = 'Times New Roman'
        font.size = Pt(70)
        name = "%d.docx" % i

        input_doc.save(name)

转载于:https://www.jianshu.com/p/46e8e9057f1e