Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to change the cell colors and border? #8

Open
aawalker9 opened this issue Feb 28, 2019 · 4 comments
Open

Way to change the cell colors and border? #8

aawalker9 opened this issue Feb 28, 2019 · 4 comments

Comments

@aawalker9
Copy link

Is there a way to change the default cell and border colors?

@robintw
Copy link
Owner

robintw commented Feb 28, 2019

It isn't supported at the moment in PandasToPowerpoint itself, but you should be able to use the python-pptx library to alter the table once PandasToPowerpoint has created it.

Use the df_to_table function to create a table from a dataframe on a specified slide of a presentation. This will return a table object (tbl in the code below) which you can use to modify the table. Then do something like this (warning, untested):

cell = tbl.table.cell(0, 0)
cell.fill.solid() # Must set fill type to solid first
cell.fill.fore_color.rgb = pptx.dml.color.RGBColor(255, 0, 0)

This should set the top left cell to have a red background.

I don't think support for borders has yet been implemented in python-pptx, so I can't yet support them in PandasToPowerpoint.

@broschke
Copy link

broschke commented Sep 6, 2019

When df_to_table writes a table to a slide, what is the table object called? I'm trying to apply formatting but using "tbl" is giving me an error.

@robintw
Copy link
Owner

robintw commented Sep 6, 2019

I haven't used this code myself for a while, but I've had a quick look at the code (see https://github.com/robintw/PandasToPowerpoint/blob/master/pd2ppt/pd2ppt.py#L126). It seems that the object returned from df_to_table is the shape object, and you can access the table from it by doing .table. So, if you run tbl = df_to_table() then you should be able to access the table as tbl.table.

@broschke
Copy link

broschke commented Sep 6, 2019

Thank you. That did it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants