{"id":23,"date":"2026-01-29T11:35:53","date_gmt":"2026-01-29T03:35:53","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=23"},"modified":"2026-01-16T06:38:44","modified_gmt":"2026-01-16T06:38:44","slug":"how-to-set-cell-styles-using-openpyx-color","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-set-cell-styles-using-openpyx-color.html","title":{"rendered":"How To Set Cell Styles Using OpenPyX &#8211; Color"},"content":{"rendered":"<h2>Method<\/h2>\n<ul>\n<li>RGB Coloring<\/li>\n<\/ul>\n<p>&gt;&gt;&gt; font = Font(color=&#8217;00FF0000&#8242;)<\/p>\n<blockquote>\n<p>&gt;&gt; font = Font(color=&#8217;FF0000&#8242;)<\/p>\n<\/blockquote>\n<p>&gt;&gt;&gt; from openpyxl.styles.colors import Color<\/p>\n<p>&gt;&gt;&gt; c = Color(rgb=&#8217;00FF00&#8242;)\u00a0\u00a0\u00a0\u00a0 #RGB Color<\/p>\n<p>&gt;&gt;&gt; font = Font(color=c)<\/p>\n<ul>\n<li>Indexed Coloring<\/li>\n<\/ul>\n<p>&gt;&gt;&gt; c = Color(indexed=32)\u00a0\u00a0\u00a0\u00a0 #Indexed Color<\/p>\n<p>&gt;&gt;&gt; font = Font(color=c)<\/p>\n<ul>\n<li>Theme Color<\/li>\n<\/ul>\n<p>Set theme color using the `theme` parameter.<\/p>\n<p>&gt;&gt;&gt; c = Color(theme=6, tint=0.5)\u00a0\u00a0\u00a0\u00a0 #Theme color<\/p>\n<p>&gt;&gt;&gt; font = Font(color=c)<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Cell Style: Setting Colors\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 the Font class\nfrom openpyxl.styles import Font\nfont=Font(color=\"00FF0000\")\n#font=Font(color=\"FF0000\")\n\n#Set font for a cell\nws.cell(row=2,column=2).font=font\nws&#91;'B2']='Test123'\n\nfrom openpyxl.styles.colors import Color\n#RGB color\nc=Color(rgb=\"00FF00\")\nfont=Font(color=c)\n\n#Set font for a cell\nws.cell(row=3,column=3).font=font\nws&#91;'C3']='Test123'\n\n#Indexed coloring\nc=Color(indexed=32)\nfont=Font(color=c)\n\n#Set font for a cell\nws.cell(row=4,column=4).font=font\nws&#91;'D4']='Test123'\n\n#Theme colors\nc=Color(theme=6,tint=0.8)\nfont=Font(color=c)\n\n#Set font for a cell\nws.cell(row=5,column=5).font=font\nws&#91;'E5']='Test123'\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\/9.png\" alt=\"Set Cell Styles Using OpenPyX - Color\" class=\"wp-image-243\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/9.png 787w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/9-300x151.png 300w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/9-768x387.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Indexed Color Table<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"223\" height=\"254\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/8.png\" alt=\"\" class=\"wp-image-244\"\/><\/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-23","post","type-post","status-publish","format-standard","hentry","category-openpyxl-cell-range"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/23","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=23"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions\/245"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}