Jer*_*nes 7 python-3.x python-pptx
我正在创建一个脚本来显示产品性能图表,并创建一个表格来显示其部件号、应用程序列表和当前应用程序的数量。
但是,默认字体大小太大,无法将所有这些信息放入幻灯片中,需要缩小。
如何在 Python-pptx 中减小表格中文本的字体大小?
这就是我所拥有的,但我不断收到错误消息“AttributeError: '_Cell' 对象没有属性 'paragraph'”
table = shapes.add_table(rows, cols, left + left_offset, top + Inches(.25), width, height - Inches(.25)).table
#column width
for i in range(3):
    table.columns[i].width = col_width[i]           
    for i in range(len(a_slide)):
        #color table
        if i % 2 == 0:
            for j in range(3):
                fill = table.cell(i, j).fill
                fill.background()
        else:
            for j in range(3):
                fill = table.cell(i, j).fill
                fill.solid()
                fill.fore_color.rgb = RGBColor(240, 128, 128)
        #populate table
        table.cell(i, 0).text = str(item["name"])
        try:
            table.cell(i, 1).text = ", ".join(item["app"])
        except:
            table.cell(i, 1).text = " "
        finally:
            table.cell(i, 2).text = str(item["vio"])
            for j in range(0,3):
                font = table.cell(i, j).paragraph[0].font
                font.size = Pt(12)
一个_Cell对象不直接包含段落。但是,它确实包括一个包含段落的TextFrame对象.text_frame。所以如果你只是使用:
cell.text_frame.paragraphs[0]
..你应该得到你所期望的。请注意,它是 .paragraphs,而不是 .paragraph。
API 文档在_Cell这里:http :
 //python-pptx.readthedocs.io/en/latest/api/table.html#cell-objects
并且通常提供解决像这样的更精细点所需的所有细节。
| 归档时间: | 
 | 
| 查看次数: | 3337 次 | 
| 最近记录: |