• 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)
  • 相关阅读:
    产生6位的随机码
    用户输入注册的小程序
    进度条的小程序
    文件的相关操作---读写与修改
    字符串分割(C++) 转载
    C++ Stream与编码转换
    wxWidgets界面设计工具DialogBlocks(转载)
    WIN32窗口模板
    WTL对话框应用程序响应键盘消息
    常用网站
  • 原文地址:https://www.cnblogs.com/2012-dream/p/10899549.html
Copyright © 2020-2023  润新知