• python-docx about unusual operating


    from docx import Document
    document = Document
    table = document.add_table(rows=2, cols=3)
    #
    set the whole table in the center position table.alignment = WD_TABLE_ALIGNMENT.CENTER
    # set every single cell center 
    for row in table.rows: row.height = Inches(1) for cell in row.cells:
               # set colums center cell.vertical_alignment
    = WD_CELL_VERTICAL_ALIGNMENT.CENTER paragraphs = cell.paragraphs for paragraph in paragraphs:
                   # set each cell center paragraph.paragraph_format.alignment
    = WD_PARAGRAPH_ALIGNMENT.CENTER for run in paragraph.runs: font = run.font font.size = Pt(22)
    row_cell = table.add_row().cells
    # choice one row row_pic
    = row_cell[0]
    # clear blank area row_pic._tc.clear_content()
    # use paragraph function pic_run
    = row_pic.add_paragraph().add_run()
    # insert a picture path as a str into a cell from a table pic_run.add_picture(
    './picture/{}'.format("picture_name.jpg"), width=Inches(5))

    one way to change the font size from paragraph:

     p = document.add_paragraph()
     # there is not just set current paragraph font size ,also set the
     #  whole word enter blank,which means every enter as size as
     # there font size. if the other paragraph set font size as this
     # way, they will change together and you should care about that.
     p.style.font.size = Pt(22)

    the other way :

      run = p.add_run(u'hello world')
      # there is another way set font size ,different from upton ,only
      # set current paragraph,the key is function ==>app_run() after it.
      run.font.size = Pt(22)
  • 相关阅读:
    如何插入和查找记录(行)(十一)
    如何查看数据表及数据表结构(十)
    如何创建数据表(九)
    MySQL常见的数据类型(八)
    MySQL数据库的常见操作(七)
    如何修改提示符(六)
    MySQL的登录和退出(五)
    如何启动和关闭MySQL?(四)
    如何配置MySQL?(三)
    如何安装MySQL?(二)
  • 原文地址:https://www.cnblogs.com/2012-dream/p/10899549.html
Copyright © 2020-2023  润新知