{"id":22,"date":"2026-01-28T17:17:16","date_gmt":"2026-01-28T09:17:16","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=22"},"modified":"2026-01-16T06:32:23","modified_gmt":"2026-01-16T06:32:23","slug":"how-to-set-cell-styles-using-openpyx-font","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-set-cell-styles-using-openpyx-font.html","title":{"rendered":"How To Set Cell Styles Using OpenPyX &#8211; Font"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin-top: 4pt; margin-bottom: 4pt; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Create a `Font` object to define the font\u2019s name, size, boldness, italics, etc. The main parameters and their descriptions are as follows:<\/p>\n<ul>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">name<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Font name.<\/span><\/li>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">size<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Font size.<\/span><\/li>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">color<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Font color.<\/span><\/li>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">bold<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Whether the font is bold.<\/span><\/li>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">italic<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Whether the font is italic.<\/span><\/li>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">underline<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Underline setting, can be &#8220;none&#8221;, &#8220;single&#8221;, or &#8220;double&#8221;.<\/span><\/li>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">strike<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Whether the font has a strike-through.<\/span><\/li>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">strikethrough<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Alternate for strike-through.<\/span><\/li>\n<li style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14pt;\"><span lang=\"en-US\" style=\"background: white;\">vertalign<\/span><span lang=\"zh-CN\" style=\"background: white;\">\uff0c<\/span><span lang=\"zh-CN\">Superscript, subscript setting, can be &#8220;superscript&#8221;, &#8220;subscript&#8221;, or &#8220;baseline&#8221;.<\/span><\/li>\n<\/ul>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Cell Style: Setting Fonts\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\n\n#Create a font\nfont=Font(name='Arial', size=12, bold=True, italic=True, \\\n          underline='single', strike=False, color='FF0000')\n\n#Set the font of a cell\nws.cell(row=3, column=3).font=font\nws&#91;'C3']='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\/7.png\" alt=\"Set Cell Styles Using OpenPyX - Font\" class=\"wp-image-240\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/7.png 787w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/7-300x151.png 300w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/7-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-22","post","type-post","status-publish","format-standard","hentry","category-openpyxl-cell-range"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/22","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=22"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":241,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions\/241"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}