{"id":21,"date":"2026-01-28T11:08:15","date_gmt":"2026-01-28T03:08:15","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=21"},"modified":"2026-01-16T06:29:36","modified_gmt":"2026-01-16T06:29:36","slug":"how-to-set-cell-styles-using-openpyx-overview","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-set-cell-styles-using-openpyx-overview.html","title":{"rendered":"How To Set Cell Styles Using OpenPyX &#8211; Overview"},"content":{"rendered":"<h2>Method<\/h2>\n<p>Import related classes to set the cell style. OpenPyXl\u00a0 has six related classes\uff1a<\/p>\n<ul>\n<li>NumberFormat<\/li>\n<li>Font<\/li>\n<li>Alignment<\/li>\n<li>PatternFill<\/li>\n<li>Border<\/li>\n<li>Protection<\/li>\n<\/ul>\n<p>Import them before using them:<\/p>\n<p>from openpyxl.styles import numbers,Font, Alignment<\/p>\n<p>from openpyxl.styles import PatternFill, Border, Side, Protection<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Working with Cell Styles\n\n#Import load_workbook function\nfrom openpyxl import Workbook\n\n#Create a new workbook\nwb=Workbook()\n#Get the active worksheet\nws=wb.active\n\n#Import cell style-related classes\nfrom openpyxl.styles import numbers,Font,Alignment\nfrom openpyxl.styles import PatternFill,Border,Side,Protection\nfrom openpyxl.styles import Font\n\n#Create fonts\nfont=Font(bold=True)\n\n#Get a cell\ncl=ws&#91;'C3']\n\n#Set the font of a cell\ncl.font=font\n\n#Set the font of a cell range\nfor row in ws&#91;'A1:C3']:\n    for cell in row:\n        cell.font = font\n\n#Set the font of a row\nrow=ws.row_dimensions&#91;1]\nrow.font=font\n\n#Set the font of a column\ncolumn=ws.column_dimensions&#91;'A']\ncolumn.font=font\n\nwb.save('test.xlsx')\nwb.close()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"787\" height=\"397\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/6.png\" alt=\"Set Cell Styles Using OpenPyX\" class=\"wp-image-237\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/6.png 787w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/6-300x151.png 300w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/6-768x387.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>OpenPyXL<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-openpyxl-cell-range"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions\/238"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}