Цветовые таблицы ячеек в ppt с использованием Python - PullRequest
0 голосов
/ 24 мая 2019

Итак, у меня есть Excel, который содержит следующую таблицу:

enter image description here

Я хочу получить ту же таблицу в powerpoint, используя Python

Работа, выполненная до сих пор :

  1. Прочитайте Excel для Python и сохраните в pandas df
  2. Добавьте df в powerpoint

Код для того же усилия:

from pd2ppt import df_to_table
import pandas as pd
from pptx import Presentation
from pptx.util import Inches

path =r"Sample PPT.pptx"
prs = Presentation(path)
title_slide_layout = prs.slide_layouts[5]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
title.text = "Summary Table"

top = Inches(1.5)
left =Inches(0.25)
width =Inches(9.25)
height= Inches(5.0)


df_to_table(slide, df,left, top, width, height)

Все, что мне нужно, это как сделать форматирование цвета в этой таблице с помощью Python?

1 Ответ

2 голосов
/ 24 мая 2019

Каждая ячейка в таблице PowerPoint имеет свою собственную fill , которая может делать все, что могут делать другие FillFormat объекты: *

from pptx.dml.color import RGBColor

cell = table.cell(0, 0)  # ---or whatever cell you choose---
fill = cell.fill
fill.solid()
fill.fore_color.rgb = RGBColor(0xFA, 0x00, 0x37)

Интерфейс объекта FillFormat дополнительноописано в документации здесь:
https://python -pptx.readthedocs.io / en / latest / api / dml.html # fillformat-objects

...