0

I have below code which generates a sample side with layout 1 with Title as Summary Table

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

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

Now in the same slide, I want a dataframe in the placeholder section.

Sample df:

df = pd.DataFrame(
    {'District':['Hampshire', 'Dorset', 'Wiltshire', 'Worcestershire'],
     'Population':[25000, 500000, 735298, 12653],
     'Ratio':[1.56, 7.34, 3.67, 8.23]})

My Code:

df_to_powerpoint(
    r"mypath\Sample PPT.pptx", df)

The above code works and gets me a df on a slide but it outputs the data in the next slide and not on the same slide where I printed title as Summary Table.

All in all, I want the df and the title in one slide

Any help please?

Rahul Agarwal
  • 4,034
  • 7
  • 27
  • 51

1 Answers1

1

Figured it out myself. Just need to to df_to_table instead of df_to_powerpoint

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)

prs.save(path)

Just need to put the code after my title.text and it worked!!

Rahul Agarwal
  • 4,034
  • 7
  • 27
  • 51
  • Could you try to answer the below question: https://stackoverflow.com/q/59464366/6389099 – RSM Dec 24 '19 at 06:56