Change font style in openpyxl
Clash Royale CLAN TAG#URR8PPP
Change font style in openpyxl
Hi I am working on setting the font style to automate the stuff and I can't get the results I want. I want to change the font of column A but I cannot find the correct command for it. Thanks for your time!
import openpyxl
from openpyxl.styles import Font
wb = openpyxl.Workbook()
sheet = wb["Sheet"]
italic24Font = Font( size = 24, italic = True)
sheet['A'] #I do not know the command here
wb.save( 'test.xlsx' )
1 Answer
1
You can use font attribute of worksheet column, something like this:
>>> my_col = sheet.column_dimensions['A']
>>> my_col.font = italic24Font
But, note that this applies only to cells created (in Excel). If you want to apply styles to entire column then you must apply the style to each cell by iteration.
Opps it appears that column was hidden. Thanks for your help!
– jy.chua
Aug 12 at 9:09
This is covered in the documentation openpyxl.readthedocs.io/en/stable/styles.html#applying-styles
– Charlie Clark
Aug 13 at 8:09
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Hello, thanks for replying! After I run the code, I opened the file test.xlsx and the whole of column A seems to have disappeared. What went wrong
– jy.chua
Aug 12 at 6:53