{"id":70,"date":"2026-02-19T11:20:16","date_gmt":"2026-02-19T03:20:16","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=70"},"modified":"2026-01-17T10:17:27","modified_gmt":"2026-01-17T10:17:27","slug":"how-to-set-color-using-xlwings-rgb","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-color-using-xlwings-rgb\/","title":{"rendered":"How To Set Color Using xlwings? &#8211; RGB"},"content":{"rendered":"<h2>Method<\/h2>\n<p>RGB color shading defines a color using the red, green, and blue components. You can set RGB color shading using the `Color` property of graphical objects. If you&#8217;re accustomed to specifying RGB components to set the color, you can use the `rgb_to_int` method from the `xlwings.utils` class to convert an RGB tuple, such as (255, 0, 0), into an integer, which can then be assigned to the `Color` property.<\/p>\n<p>shp=sht.api.Shapes.AddShape(9, 50, 50, 100, 100)<\/p>\n<p>shp.Fill.ForeColor.RGB=xw.utils.rgb_to_int((0, 255,0))<\/p>\n<p>shp.Line.ForeColor.RGB=xw.utils.rgb_to_int((0,0,255))<\/p>\n<p>shp.Line.ForeColor.RGB=16711680\u00a0\u00a0\u00a0 # or 0x0000FF<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Color - RGB\n\nimport xlwings as xw    #Import xlwings package\n\napp=xw.App()\nbk=app.books.active   #Get the active workbook\nsht=bk.sheets.active    #Get the active worksheet\n\nshp=sht.api.Shapes.AddShape(9, 50, 50, 100, 100)\n#shp.Fill.ForeColor.RGB=xw.utils.rgb_to_int((0, 255,0))\nshp.Line.ForeColor.RGB=xw.utils.rgb_to_int((0,0,255))\n\nshp.Fill.ForeColor.RGB=0x0000FF    # or 16711680\n\n#bk.save()\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=\"773\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/68.png\" alt=\"Set Color Using xlwings? - RGB\" class=\"wp-image-408\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/68.png 773w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/68-300x187.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/68-768x479.png 768w\" sizes=\"auto, (max-width: 773px) 100vw, 773px\" \/><\/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":[10],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-xlwings-shape"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/70","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=70"}],"version-history":[{"count":4,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":410,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/70\/revisions\/410"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}