I have a dataframe that looks like this:
c sp k1 k2 k3 k4 k5 k6
0 c1 70.73 0.3% 0.6% 0.7% 0.8% 0.7% 0.5%
1 c2 149.71 0.7% 0.6% 0.4% 0.6% 0.7% 1.0%
2 c3 -1.00 0.0% 0.0% 0.0% 0.0% 0.0% 0.0%
3 c4 24.88 0.1% 0.9% 0.5% 0.7% 0.7% 0.9%
4 c5 276.23 0.3% 2.3% 0.4% 2.0% 1.9% 1.9%
I am creating a slide in a ppt for this table by using this code:
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[0])
title = slide.shapes.title
title.text = "Title"
title.top = Cm(1) # set title position
title.left = Cm(1) # set title position
title.width = Cm(24) # set title size
title.height = Cm(2) # set title size
top = Inches(1.5) # set table position
left = Inches(0.25) # set table position
width = Inches(9.25) # set table size
height = Inches(5.0) # set table size
tbl1 = df_to_table(slide, dt, left, top, width, height, name='tbl1')
# changing the font size and font of the whole table
for cell in iter_cells(tbl1.table):
for paragraph in cell.text_frame.paragraphs:
for run in paragraph.runs:
run.font.size = Pt(12)
run.font.name = 'Calibri'
prs.save('test.pptx')
I am struggling in applied the following changes in this table though
1- I would like to add thick top and bottom border at the column names
2- Right border at the column sp
3- Make red color the font color of all the c
s that have negative sp
4- Apply green color formatting in all the cells in k
columns so that the higher the value the darker the green of the cell
5- Adjust the size of the cells, so that the text of the cell autofits the cell
I am not really sure if all these formatting changes are possible using the pptx
package
Note: The df_to_table
function comes from here