{"id":2054,"date":"2026-05-10T16:30:18","date_gmt":"2026-05-10T08:30:18","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2054"},"modified":"2026-03-28T05:50:55","modified_gmt":"2026-03-28T05:50:55","slug":"how-to-use-applicationcharts-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationcharts-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.Charts in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Charts<\/code> member of the <code>Application<\/code> object in Excel&#8217;s object model represents the collection of all chart sheets in a workbook. In xlwings, this is accessed via the <code>api<\/code> property, which provides direct access to the underlying Excel object model. This allows for advanced chart management, such as adding new chart sheets, modifying existing ones, or iterating through all charts in the application. Using <code>Charts<\/code> is particularly useful when you need to work with chart sheets specifically, as opposed to embedded charts within worksheets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The <code>Charts<\/code> collection enables you to create, access, and manipulate chart sheets. Chart sheets are standalone sheets that contain only a chart, separate from worksheet data. You can add new chart sheets, reference existing ones by name or index, and perform operations like copying, moving, or deleting them. This is essential for automating report generation or dashboard creation where charts need to be organized independently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax:<\/strong><br>In xlwings, you typically access <code>Charts<\/code> through the workbook or application context. The general syntax is:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>app.api.Charts<\/code>: Returns the <code>Charts<\/code> collection for the entire Excel application, including all open workbooks.<\/li>\n\n\n\n<li><code>wb.api.Charts<\/code>: Returns the <code>Charts<\/code> collection for a specific workbook (where <code>wb<\/code> is a workbook object).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Key methods and properties include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Add([Before], [After], [Count])<\/code>: Adds new chart sheets. Parameters are optional: <code>Before<\/code> and <code>After<\/code> specify the sheet position (as a sheet object), and <code>Count<\/code> sets the number of sheets to add (default is 1).<\/li>\n\n\n\n<li><code>Item(Index)<\/code>: Returns a single <code>Chart<\/code> object by index (integer) or name (string).<\/li>\n\n\n\n<li><code>Count<\/code>: Property that returns the number of chart sheets in the collection.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For parameters like <code>Before<\/code> and <code>After<\/code>, you can use sheet references, such as <code>wb.sheets['Sheet1'].api<\/code>, to position the new chart sheet relative to existing sheets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Examples:<\/strong><br>Here are xlwings API code examples demonstrating the use of the <code>Charts<\/code> member:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Adding a new chart sheet to a workbook:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to an existing workbook or create a new one\nwb = xw.Book('example.xlsx')\napp = xw.apps.active\n\n# Add a new chart sheet named \"SalesChart\" at the end\nnew_chart = wb.api.Charts.Add()\nnew_chart.Name = \"SalesChart\"\nprint(f\"Added chart sheet: {new_chart.Name}\")<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Accessing and iterating through all chart sheets in the application:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\n\n# Count the total chart sheets across all open workbooks\ntotal_charts = app.api.Charts.Count\nprint(f\"Total chart sheets in application: {total_charts}\")\n\n# Iterate through each chart sheet and print its name\nfor chart in app.api.Charts:\nprint(chart.Name)<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Creating a chart sheet with specific positioning:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwb = xw.Book('data.xlsx')\n# Add a chart sheet before the first worksheet\nfirst_sheet = wb.sheets&#91;0].api\nnew_chart = wb.api.Charts.Add(Before=first_sheet)\nnew_chart.Name = \"AnalysisChart\"\n\n# You can then use the Chart object to set data sources or formats\n# For example, set a chart type (assuming data is prepared)\nnew_chart.ChartType = 51 # 51 corresponds to xlLineMarkers in Excel constants<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Deleting a chart sheet by name:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwb = xw.Book('report.xlsx')\n# Delete a chart sheet named \"OldChart\"\ntry:\n    wb.api.Charts(\"OldChart\").Delete()\n    print(\"Deleted chart sheet: OldChart\")\nexcept Exception as e:\n    print(f\"Error: {e}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Charts` member of the `Application` object in Excel&apos;s object model represents the collection of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2054","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2054","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=2054"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2054\/revisions"}],"predecessor-version":[{"id":3142,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2054\/revisions\/3142"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}