{"id":2253,"date":"2026-08-18T07:07:37","date_gmt":"2026-08-17T23:07:37","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2253"},"modified":"2026-03-28T11:56:49","modified_gmt":"2026-03-28T11:56:49","slug":"how-to-use-workbookitem-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-workbookitem-in-the-xlwings-api-way\/","title":{"rendered":"How to use Workbook.Item in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Item<\/code> member of the <code>Workbook<\/code> object in the Excel object model is a property that provides access to individual worksheets or charts within a workbook by their index number or name. In xlwings, this functionality is not exposed through an explicit <code>Item<\/code> property as in VBA, but is instead accessed directly through the workbook&#8217;s indexing or via methods like <code>.sheets[]<\/code>. This design offers a more Pythonic and intuitive way to retrieve specific sheets, aligning with common Python container behaviors.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality<\/strong><br>The primary function is to return a single <code>Sheet<\/code> object (which can be a <code>Worksheet<\/code> or <code>Chart<\/code> object) from the <code>Sheets<\/code> collection of a workbook. This allows for targeted operations on a specific sheet, such as reading data, writing values, or formatting cells, without needing to activate or select it first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax &amp; Parameters<\/strong><br>In xlwings, you access a sheet by its index or name using the <code>sheets<\/code> property of a <code>Book<\/code> object (xlwings&#8217; equivalent of a <code>Workbook<\/code>). The syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sheet = wb.sheets&#91;index_or_name]<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>wb<\/code>: The xlwings <code>Book<\/code> object instance.<\/li>\n\n\n\n<li><code>index_or_name<\/code>: This parameter can be:<\/li>\n\n\n\n<li>An <code>int<\/code> representing the sheet&#8217;s position (1-based index). For example, <code>1<\/code> refers to the first sheet tab from the left.<\/li>\n\n\n\n<li>A <code>str<\/code> representing the exact name of the sheet as it appears on its tab.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Unlike the VBA <code>Item<\/code> property, xlwings does not use a separate property call; the indexing is performed directly on the <code>sheets<\/code> collection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples<\/strong><br>Here are practical examples demonstrating how to use this functionality in xlwings:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Accessing a sheet by its index:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n# Connect to an existing workbook (ensure Excel is open or use app.books.open)\napp = xw.App(visible=False)\nwb = app.books.open(r'C:\\path\\to\\your\\workbook.xlsx')\n# Access the first worksheet in the workbook\nfirst_sheet = wb.sheets&#91;1]\n# Read a value from cell A1 of the first sheet\nvalue_a1 = first_sheet.range('A1').value\nprint(value_a1)\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Accessing a sheet by its name:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n# Start a new instance of Excel and create a new workbook\napp = xw.App()\nwb = app.books.add()\n# Rename the first sheet for demonstration\nwb.sheets&#91;0].name = 'SalesData'\n# Access the sheet by its exact name\nsales_sheet = wb.sheets&#91;'SalesData']\n# Write a value to cell B5\nsales_sheet.range('B5').value = 'Quarterly Revenue'\n# Save and close\nwb.save('report.xlsx')\nwb.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Iterating through all sheets using the collection:<\/strong><br>While the <code>Item<\/code> concept is for single access, you can loop through the <code>sheets<\/code> collection, which is the parent of the <code>Item<\/code>.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book('data_workbook.xlsx')\n# Print the name of every sheet in the workbook\nfor sheet in wb.sheets:\n    print(sheet.name)\n    # You could perform operations on each 'sheet' object here\nwb.close()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Item` member of the `Workbook` object in the Excel object model is a property that provides acc&#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-2253","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2253","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=2253"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2253\/revisions"}],"predecessor-version":[{"id":3442,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2253\/revisions\/3442"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}