跳至主要內容

生成docx文件

爱喝水的木子...小于 1 分钟pythonpptofficepython

脚本生成docx文件

temp_code = {"x":["张三","张三","张三"],"y":["张三","张三","张三"],"z":["张三","张三","张三"]}
import json

from docx import Document
from docx.oxml.ns import qn
from docx.shared import Pt, RGBColor


def create_docx(doc_name, text_list):
    doc = Document()
    doc.styles['Normal'].font.name = u'宋体'
    doc.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
    doc.styles['Normal'].font.size = Pt(10.5)
    doc.styles['Normal'].font.color.rgb = RGBColor(0, 0, 0)
    for item in text_list:
        doc.add_paragraph(item)
    doc.save(doc_name)
for k, v in temp_code.items():
    _doc_name = k + ".docx"
    create_docx(_doc_name, v)
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v3.1.3