{"id":45,"date":"2026-02-06T17:23:50","date_gmt":"2026-02-06T09:23:50","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=45"},"modified":"2026-01-17T05:29:32","modified_gmt":"2026-01-17T05:29:32","slug":"how-to-set-cell-font-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-cell-font-using-xlwings\/","title":{"rendered":"How To Set Cell Font Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>#xlwings API<\/p>\n<p>sht.api.Range(&#8216;A1:E1&#8217;).Font.Name = &#8216;Arial&#8217;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Set the font to Arial<\/p>\n<p>sht.api.Range(&#8216;A1:E1&#8217;).Font.ColorIndex = 3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Set the font color to red<\/p>\n<p>sht.api.Range(&#8216;A1:E1&#8217;).Font.Size = 20\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Set the font size to 20<\/p>\n<p>sht.api.Range(&#8216;A1:E1&#8217;).Font.Bold = True\u00a0\u00a0\u00a0\u00a0\u00a0 #Set the font to bold<\/p>\n<p>sht.api.Range(&#8216;A1:E1&#8217;).Font.Italic = True\u00a0\u00a0\u00a0\u00a0\u00a0 #Set the font to italic<\/p>\n<p>sht.api.Range(&#8216;A1:E1&#8217;).Font.Underline=xw.constants.UnderlineStyle.xlUnderlineStyleDouble\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Add a double underline to the text<\/p>\n<p>sht.api.Range(&#8216;C1&#8242;).Value=&#8217;Test123&#8217;<\/p>\n<p>\u00a0<\/p>\n<p>sht.api.Range(&#8216;A3:E3&#8217;).Font.Color =xw.utils.rgb_to_int((0, 0, 255))<\/p>\n<p>#sht.api.Range(&#8216;A3:E3&#8217;).Font.Color =16711680\u00a0\u00a0\u00a0 # or 0x0000FF<\/p>\n<p>#sht.api.Range(&#8216;A1:E1&#8217;).Font.ColorIndex = 3<\/p>\n<p>#sht.api.Range(&#8216;A3:E3&#8217;).Font.ThemeColor =5<\/p>\n<p>sht.api.Range(&#8216;C3&#8242;).Value=&#8217;Test456&#8217;<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Cell Font Styles\n\nimport xlwings as xw    #Import the xlwings package\n\napp=xw.App()\nbk=app.books.active    #Get the active workbook\nsht=bk.sheets.active    #Get the active worksheet\n\n#xlwings API\nsht.api.Range('A1:E1').Font.Name = 'Arial'       #Set the font to Arial\nsht.api.Range('A1:E1').Font.ColorIndex = 3       #Set the font color to red\nsht.api.Range('A1:E1').Font.Size = 20       #Set the font size to 20\nsht.api.Range('A1:E1').Font.Bold = True      #Set the font to bold\nsht.api.Range('A1:E1').Font.Italic = True      #Set the font to italic\nsht.api.Range('A1:E1').Font.Underline=xw.constants.UnderlineStyle.xlUnderlineStyleDouble       #Add a double underline to the text\nsht.api.Range('C1').Value='Test123'\n\nsht.api.Range('A3:E3').Font.Color =xw.utils.rgb_to_int((0, 0, 255))\n#sht.api.Range('A3:E3').Font.Color =16711680    # \u62160x0000FF\n#sht.api.Range('A1:E1').Font.ColorIndex = 3\n#sht.api.Range('A3:E3').Font.ThemeColor =5\nsht.api.Range('C3').Value='Test456'\n\n#bk.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/39.png\" alt=\"Set Cell Font Using xlwings\" class=\"wp-image-322\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/39.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/39-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/39-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-xlwings-cell-range"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":323,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/45\/revisions\/323"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}