{"id":62,"date":"2026-02-15T11:27:27","date_gmt":"2026-02-15T03:27:27","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=62"},"modified":"2026-01-17T06:10:54","modified_gmt":"2026-01-17T06:10:54","slug":"how-to-create-curves-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-curves-using-xlwings\/","title":{"rendered":"How To Create Curves Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>Use the `AddCurve` method of the Shapes object to create a curve. The method syntax is:<\/p>\n<p>\u00a0<\/p>\n<p>sht.api.Shapes.AddCurve(SafeArrayOfPoints)<\/p>\n<p>\u00a0<\/p>\n<p>Where `sht` refers to a worksheet object. The parameter `SafeArrayOfPoints` specifies the coordinates of the Bezier curve&#8217;s vertices and control points. The number of points should always be 3n + 1, where n is the number of line segments in the curve. This method returns a Shape object representing the Bezier curve.<\/p>\n<p>\u00a0<\/p>\n<p>Vertices are represented by their x and y coordinates as pairs, and all vertices are provided as a 2D list. For example:<\/p>\n<p>\u00a0<\/p>\n<p>pts=[[0,0],[72,72],[100,40],[20,50],[90,120],[60,30],[150,90]]<\/p>\n<p>\u00a0<\/p>\n<p>Use the COMTypes package for drawing:<\/p>\n<p>from comtypes.client import CreateObject<\/p>\n<p>app2=CreateObject(&#8220;Excel.Application&#8221;)<\/p>\n<p>app2.Visible=True<\/p>\n<p>bk2=app2.Workbooks.Add()<\/p>\n<p>sht2=bk2.Sheets(1)<\/p>\n<p>pts=[[0,0],[72,72],[100,40],[20,50],[90,120],[60,30],[150,90]]\u00a0 #\u9876\u70b9<\/p>\n<p>sht2.Shapes.AddCurve(pts)\u00a0\u00a0\u00a0 #Add Bezier curve<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Auto-fill formulas\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'\\AutoFill.xlsx',read_only=False)\nsht=bk.api.Sheets(1)    #Get the worksheet\n\n#Auto-fill formulas\nsht.Range('C1').Formula='=$A1+$B1'\nsht.Range('C1:C5').FillDown()\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=\"795\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/60.png\" alt=\"Create Curves Using xlwings\" class=\"wp-image-377\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/60.png 795w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/60-300x182.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/60-768x466.png 768w\" sizes=\"auto, (max-width: 795px) 100vw, 795px\" \/><\/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-62","post","type-post","status-publish","format-standard","hentry","category-xlwings-shape"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/62","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=62"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":378,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions\/378"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}