Beispiel #1
0
    def appendix_two(self, nom_akt='ГГГГ.ММ.ДД-ХХХХ ТБ'):
        self.wordDoc = Document(r'\Example.docx')
        style = self.wordDoc.styles['Normal']
        font = style.font
        font.name = 'Times New Roman'
        font.size = shared.Pt(11)

        p1 = self.wordDoc.paragraphs[0]
        p1.add_run('Text').italic = True
        p1.alignment = 2
        p2 = self.wordDoc.add_paragraph()
        p2.add_run('№' + nom_akt).italic = True
        p2.alignment = 2

        p3 = self.wordDoc.add_paragraph()
        p3.add_run('Дополнение TEXT2').bold = True
        p3.alignment = 1
        p3.italic = False

        p4 = self.wordDoc.add_paragraph()
        p4.add_run('Выводы о TEXT3').bold = True
        p4.alignment = 1
        p4.italic = False
def formatParagraph(index, font_name, size):
    to_format = document.paragraphs[index].runs[0]
    to_format.font.name = font_name
    to_format.font.size = shared.Pt(size)
Beispiel #3
0
from docx import Document
from docx.enum.table import WD_TABLE_ALIGNMENT
from docx.enum.table import WD_TABLE_DIRECTION

# 打开文档
tagDocument = Document()

# 新增自定义样式
styles = tagDocument.styles

paragraph_styles = [s for s in styles if s.type == WD_STYLE_TYPE.PARAGRAPH][0]
character_styles = [s for s in styles if s.type == WD_STYLE_TYPE.CHARACTER][0]
table_styles = [s for s in styles if s.type == WD_STYLE_TYPE.TABLE][0]

# 设置与上一段间隔 Pt(5)
paragraph_styles.paragraph_format.space_after = shared.Pt(5)
# 设置与下一段间隔 Pt(10)
paragraph_styles.paragraph_format.space_before = shared.Pt(10)
# 行间距
paragraph_styles.paragraph_format.line_spacing = shared.Pt(18)

paragraph_styles.font.name = u'宋体'
paragraph_styles._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')

paragraph_styles.font.size = shared.Pt(15)
paragraph_styles.font.color.rgb = RGBColor(0, 0, 0)
paragraph_styles.font.underline = False

character_styles.font.name = u'宋体'
character_styles.font.size = shared.Pt(15)
character_styles.font.underline = True