Apply the word format to create a template

# Simple template to apply - apply a small amount of change
from the Document docx Import
from docx.enum.text Import WD_ALIGN_PARAGRAPH
from docx.shared Import Pt
from docx.oxml.ns Import qn

dog_list = [ 'Husky', 'Cai', ' Alaska ']
for Change in dog_list:


    Document = the Document ()
    document.styles [' Normal '.] font.name = U' blackbody '
    document.styles [' Normal '.] element.rPr.rFonts.set (Qn (' w: eastAsia '), u' blackbody ')

    DEF add_context (context):
        P = document.add_paragraph ()
        p.alignment WD_ALIGN_PARAGRAPH.LEFT =
        R & lt p.add_run = (STR (context))
        r.font.size of Pt = ( 16)
        p.space_after of Pt = (. 5)
        P.Pt = space_before (5)


    add_context ( 'Today the weather is good,% s wake up early to go to school'% change)
    add_context ( 'This is a new line')
    Document.Save (r'C:. \ the Users \ 13375 \ Desktop \ Python \ red% s.docx '% change)

Guess you like

Origin www.cnblogs.com/tomhu/p/12342958.html