{"id":74,"date":"2026-02-21T11:54:43","date_gmt":"2026-02-21T03:54:43","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=74"},"modified":"2026-01-17T10:24:31","modified_gmt":"2026-01-17T10:24:31","slug":"how-to-set-line-properties-using-xlwings-color-line-style-and-line-width","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-line-properties-using-xlwings-color-line-style-and-line-width\/","title":{"rendered":"How To Set Line Properties Using xlwings? &#8211; Color, Line Style, and Line Width"},"content":{"rendered":"<h2>Method<\/h2>\n<p>In Excel, line objects are represented by the `LineFormat` object. The `Line` property of a `Shape` object returns a `LineFormat` object. For example, a straight line, the borders of a rectangle, and a circular region are all represented as `LineFormat` objects.<\/p>\n<p>\u00a0<\/p>\n<p>Once you have the `LineFormat` object, you can use its properties and methods to set various attributes like color, line style, line width, arrows, transparency, and pattern fill.<\/p>\n<p>\u00a0<\/p>\n<p>shp=sht.api.Shapes.AddLine(20, 20, 100, 120)<\/p>\n<p>lf=shp.Line<\/p>\n<p>lf.ForeColor.RGB=xw.utils.rgb_to_int((255,0,0))\u00a0\u00a0\u00a0 #Red<\/p>\n<p>lf.DashStyle=5\u00a0\u00a0\u00a0 #Line style, dotted line<\/p>\n<p>lf.Weight=3\u00a0\u00a0\u00a0 #Line width<\/p>\n<p>\u00a0<\/p>\n<p>shp2=sht.api.Shapes.AddShape(9, 200, 30, 120, 80)<\/p>\n<p>#Line shape in elliptical area, i.e., the boundary of the area<\/p>\n<p>lf2=shp2.Line<\/p>\n<p>lf2.ForeColor.RGB=xw.utils.rgb_to_int((255,0,0))\u00a0\u00a0\u00a0 #Red<\/p>\n<p>lf2.DashStyle=3\u00a0\u00a0\u00a0 #Line style, dotted line with circles<\/p>\n<p>lf2.Weight=4\u00a0\u00a0\u00a0 #Line width<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Line properties\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.AddLine(20, 20, 100, 120)\nlf=shp.Line\nlf.ForeColor.RGB=xw.utils.rgb_to_int((255,0,0))    #Red\nlf.DashStyle=5    #Line style, dotted line\nlf.Weight=3    #Line width\n\nshp2=sht.api.Shapes.AddShape(9, 200, 30, 120, 80)\n#Line shape in elliptical area, i.e., the boundary of the area\nlf2=shp2.Line\nlf2.ForeColor.RGB=xw.utils.rgb_to_int((255,0,0))    #Red\nlf2.DashStyle=3    #Line style, dotted line with circles\nlf2.Weight=4    #Line width\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=\"812\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/image-2.png\" alt=\"Set Line Properties Using xlwings? - Color, Line Style, and Line Width\" class=\"wp-image-420\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/image-2.png 812w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/image-2-300x178.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/image-2-768x456.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/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-74","post","type-post","status-publish","format-standard","hentry","category-xlwings-shape"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/74","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=74"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":422,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/74\/revisions\/422"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}