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

2018-10-30  本文已影响14人  Leo_23

批量生成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)

上一篇下一篇

猜你喜欢

热点阅读