2

I have a data-farme which looks like:

          yyyymm      A_growth         B_growth
         201911        NaN              NaN
         201912       -1.0             -3.0
         202001       14.0             20.0
         202002        7.0              9.0
         202003       -2.0            -14.0
         202004      -44.0            -44.0
         202005       20.0              6.0
         202006       24.0             27.0
         202007       -7.0             -1.0

I want to directly export it to power point at bottom right of slide as a small table.

One way is to create table and then use for loops to fill each cell in the table which is time consuming.

How can I use python-pptx module to directly export this table to power point.?

I am using blank_slide_layout = prs.slide_layouts[6] layout 6.

MAC
  • 1,345
  • 2
  • 30
  • 60
  • If this is just a single table, you can export it to a CSV / Excel file and link your slide to the file. Going through `python-pptx` is only worth it if you have a lot of tables to export to PowerPoint – Code Different Oct 13 '20 at 18:24
  • I have around 95 such slides and using for loop for each slide. – MAC Oct 13 '20 at 18:30
  • There is no faster way in `python-pptx`, but I can't imagine this taking more than a millisecond for each table. Why do you say it's time-consuming? – scanny Oct 13 '20 at 18:42

1 Answers1

1

You can use the add_table() function: (see docs)

df = pd.DataFrame({'hi': [1, 2, 3], 'there': ['a', 'b', 'c']})
x, y, cx, cy = Inches(2), Inches(2), Inches(4), Inches(1.5)
shape = slide.shapes.add_table(3, 3, x, y, cx, cy)
table = shape.table
cell = table.cell(1, 2)
cell.text = str(df.iloc[1][2])
moomima
  • 1,200
  • 9
  • 12