{"id":59,"date":"2026-02-13T18:20:32","date_gmt":"2026-02-13T10:20:32","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=59"},"modified":"2026-01-17T06:04:48","modified_gmt":"2026-01-17T06:04:48","slug":"how-to-create-line-segments-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-line-segments-using-xlwings\/","title":{"rendered":"How To Create Line Segments Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>Use the `AddLine` method of the Shapes object to create a line segment. The method syntax is:<\/p>\n<p>\u00a0<\/p>\n<p>sht.api.Shapes.AddLine(BeginX, BeginY, EndX, EndY)<\/p>\n<p>\u00a0<\/p>\n<p>Where `sht` refers to a worksheet object. The parameters `BeginX, BeginY` represent the coordinates of the starting point, and `EndX, EndY` represent the coordinates of the endpoint. This method returns a Shape object representing the line segment.<\/p>\n<p>\u00a0<\/p>\n<p>shp=sht.api.Shapes.AddLine(10,10,250,250)\u00a0\u00a0\u00a0 #Create a line segment `Shape` object<\/p>\n<p>ln=shp.Line\u00a0\u00a0\u00a0 #Get the line shape object<\/p>\n<p>#Set properties of the line shape object: line style, color, and width<\/p>\n<p>ln.DashStyle=3<\/p>\n<p>ln.ForeColor.RGB=xw.utils.rgb_to_int((255, 0, 0))<\/p>\n<p>ln.Weight=5<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Check if a specified cell range contains a formula\n\nimport xlwings as xw    #Import the xlwings package\nimport os    #Import the os package\n\nroot = os.getcwd()    #Get the current path\n#Create an Excel application window, visible, \n#without opening a workbook  \napp=xw.App(visible=True, add_book=False)\n#Open a data file, writable\nbk=app.books.open(fullname=root+r'\\Formula2.xlsx',read_only=False)\nsht=bk.api.Sheets(1)    #Get the worksheet\n\n#Check if a specified cell range contains a formula\nrng=sht.Range('B3:E5')\nfor cell in rng:\n    if cell.HasFormula==True:\n        print(cell.Row,cell.Column,'Yes')\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=\"807\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/57.png\" alt=\"Create Line Segments Using xlwings\" class=\"wp-image-368\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/57.png 807w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/57-300x179.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/57-768x459.png 768w\" sizes=\"auto, (max-width: 807px) 100vw, 807px\" \/><\/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-59","post","type-post","status-publish","format-standard","hentry","category-xlwings-shape"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/59","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=59"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":369,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions\/369"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}