{"id":98,"date":"2026-03-05T11:41:18","date_gmt":"2026-03-05T03:41:18","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=98"},"modified":"2026-01-17T11:17:08","modified_gmt":"2026-01-17T11:17:08","slug":"how-to-create-a-chart-worksheet-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-a-chart-worksheet-using-xlwings\/","title":{"rendered":"How To Create a Chart Worksheet Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">To create a chart worksheet (a chart that occupies the entire worksheet), use the `Add` method from the `Charts` collection. The syntax is as follows:<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; margin-left: .375in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">wb.api.Charts.Add(Before,After,Count,Type)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Here, `wb` represents the specified workbook object. The parameters are optional and are explained as follows:<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">&#8211; `Before` \u2013 Specifies a worksheet object, and the newly created chart worksheet will be placed before this worksheet.<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">&#8211; `After` \u2013 Specifies a worksheet object, and the newly created chart worksheet will be placed after this worksheet.<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">&#8211; `Count` \u2013 Specifies the number of chart worksheets to add. The default value is 1.<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">&#8211; `Type` \u2013 Specifies the chart type to add.<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Note: If both `Before` and `After` are omitted, the newly created chart worksheet will be inserted before the active worksheet.<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 10.0pt;\">\u00a0<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">cht=wb.api.Charts.Add()<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">cht.SetSourceData(Source=sht.api.Range(&#8220;A1:H7&#8221;), PlotBy=1)<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">cht.ChartType=xw.constants.ChartType.xlColumnClustered<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">cht.HasTitle=True<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Create chart worksheet\n\nimport xlwings as xw\nimport os\n\nroot=os.getcwd()\napp=xw.App(visible=True, add_book=False)\nwb=app.books.open('GDP.xlsx',read_only=False)\nsht=wb.sheets('Sheet1')\n\ncht=wb.api.Charts.Add()\ncht.SetSourceData(Source=sht.api.Range(\"A1:H7\"), PlotBy=1)\ncht.ChartType=xw.constants.ChartType.xlColumnClustered\ncht.HasTitle=True\n\n#wb.save()\n#wb.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"569\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-8.png\" alt=\"Create a Chart Worksheet Using xlwings\" class=\"wp-image-479\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-8.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-8-300x193.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-8-768x495.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/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":[8],"tags":[],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/98","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=98"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/98\/revisions\/481"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}