{"id":61,"date":"2026-02-14T17:53:24","date_gmt":"2026-02-14T09:53:24","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=61"},"modified":"2026-01-17T06:08:54","modified_gmt":"2026-01-17T06:08:54","slug":"how-to-create-polylines-and-polygons-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-polylines-and-polygons-using-xlwings\/","title":{"rendered":"How To Create Polylines and Polygons Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>To draw polylines, polygons, and curves with xlwings, there are some issues. Use another Python package called `comtypes`, which is based on COM, similar to xlwings.<\/p>\n<p>\u00a0<\/p>\n<p>First, install the `comtypes` library using the `pip` command in the DOS command window:<\/p>\n<p>\u00a0<\/p>\n<p>pip install comtypes<\/p>\n<p>\u00a0<\/p>\n<p>Then, enter the following in the Python IDLE window:<\/p>\n<p>\u00a0#Import the CreateObject function from comtypes<\/p>\n<p>from comtypes.client import CreateObject<\/p>\n<p>app2=CreateObject(&#8220;Excel.Application&#8221;)\u00a0\u00a0\u00a0 #Create Excel application<\/p>\n<p>app2.Visible=True\u00a0 #Make the application window visible<\/p>\n<p>bk2=app2.Workbooks.Add()\u00a0\u00a0\u00a0 #Add a workbook<\/p>\n<p>sht2=bk2.Sheets(1)\u00a0 #Get the first sheet<\/p>\n<p>pts=[[10,10], [50,150],[90,80], [70,30], [10,10]]\u00a0\u00a0\u00a0 #Polygon vertices<\/p>\n<p>sht2.Shapes.AddPolyline(pts)\u00a0\u00a0\u00a0 #Add polygon region<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Set to manual calculation\n\nfrom xlwings import constants as con\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#Set to manual calculation\napp.api.Calculation=con.Calculation.xlCalculationManual\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=\"762\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/59.png\" alt=\"Create Polylines and Polygons Using xlwings\" class=\"wp-image-374\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/59.png 762w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/59-300x190.png 300w\" sizes=\"auto, (max-width: 762px) 100vw, 762px\" \/><\/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-61","post","type-post","status-publish","format-standard","hentry","category-xlwings-shape"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/61","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=61"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":375,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/61\/revisions\/375"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}