{"id":2181,"date":"2026-07-13T07:33:35","date_gmt":"2026-07-12T23:33:35","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2181"},"modified":"2026-03-28T09:42:41","modified_gmt":"2026-03-28T09:42:41","slug":"how-to-use-applicationsheets-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationsheets-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.Sheets in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Application.Sheets<\/code> property in Excel&#8217;s object model provides a collection of all sheets within the open workbook, encompassing both worksheets and chart sheets. In xlwings, this is accessed via the <code>app<\/code> object, which represents the Excel application instance. The primary function is to retrieve a list or a specific sheet, enabling operations across multiple sheets or referencing sheets by name or index. This is essential for automating tasks that involve iterating through all sheets, checking their properties, or performing bulk operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>The property is accessed as <code>app.sheets<\/code>. It returns a <code>Sheets<\/code> collection object. To reference a specific sheet, you can use indexing or a sheet name.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>app.sheets<\/code>: Returns the collection of all sheets.<\/li>\n\n\n\n<li><code>app.sheets[index]<\/code>: Returns the sheet at the specified index (1-based).<\/li>\n\n\n\n<li><code>app.sheets[name]<\/code>: Returns the sheet with the given name.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>index<\/code>: An integer representing the sheet&#8217;s position in the workbook (starting from 1). For example, <code>app.sheets[1]<\/code> refers to the first sheet.<\/li>\n\n\n\n<li><code>name<\/code>: A string representing the exact name of the sheet, such as <code>app.sheets[\"Sheet1\"]<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Iterate through all sheets and print names:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False)\nwb = app.books.open('example.xlsx')\nfor sheet in app.sheets:\n    print(sheet.name)\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Access a specific sheet by name and modify a cell:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False)\nwb = app.books.open('example.xlsx')\ntarget_sheet = app.sheets&#91;\"DataSheet\"]\ntarget_sheet.range(\"A1\").value = \"Updated Value\"\nwb.save()\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Count the number of sheets and check types:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False)\nwb = app.books.open('example.xlsx')\nsheet_count = len(app.sheets)\nprint(f\"Total sheets: {sheet_count}\")\n# To check if a sheet is a worksheet (vs. chart sheet), use its type property\nfor sheet in app.sheets:\nif sheet.type == 'chart':\n    print(f\"{sheet.name} is a chart sheet.\")\nelse:\n    print(f\"{sheet.name} is a worksheet.\")\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Add a new sheet and rename it using the collection:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False)\nwb = app.books.open('example.xlsx')\nnew_sheet = wb.sheets.add()\nnew_sheet.name = \"Analysis\"\n# Access via app.sheets to confirm\nprint(\"Sheet names:\", &#91;s.name for s in app.sheets])\nwb.save()\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Application.Sheets` property in Excel&apos;s object model provides a collection of all sheets within&#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-2181","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2181","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=2181"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2181\/revisions"}],"predecessor-version":[{"id":3336,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2181\/revisions\/3336"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}