{"id":2354,"date":"2026-10-07T15:22:03","date_gmt":"2026-10-07T07:22:03","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2354"},"modified":"2026-03-29T09:47:23","modified_gmt":"2026-03-29T09:47:23","slug":"how-to-use-worksheettype-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-worksheettype-in-the-xlwings-api-way\/","title":{"rendered":"How to use Worksheet.Type in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Type<\/code> member of the <code>Worksheet<\/code> object in the Excel object model represents the type of sheet, such as a standard worksheet, a chart sheet, or a macro sheet. In xlwings, this property is accessible via the <code>api<\/code> property, which provides direct access to the underlying Excel object model. This is particularly useful when you need to programmatically determine the nature of a sheet within a workbook, enabling conditional logic based on sheet type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The primary function is to identify the sheet type. Common values include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>xlWorksheet<\/code> (a standard worksheet, value -4167)<\/li>\n\n\n\n<li><code>xlChart<\/code> (a chart sheet, value -4109)<\/li>\n\n\n\n<li><code>xlExcel4MacroSheet<\/code> (an Excel version 4 macro sheet, value 3)<\/li>\n\n\n\n<li><code>xlExcel4IntlMacroSheet<\/code> (an international macro sheet, value 4)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax:<\/strong><br>The property is accessed through the xlwings <code>Sheet<\/code> object&#8217;s <code>api<\/code> property. The <code>Sheet<\/code> object in xlwings corresponds to both worksheets and chart sheets. The syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sheet_type = sheet.api.Type<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Where <code>sheet<\/code> is an xlwings <code>Sheet<\/code> object. The <code>Type<\/code> property is read-only and returns an integer value (a <code>XlSheetType<\/code> enumeration constant).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><br>The following xlwings code demonstrates how to check the type of each sheet in the active workbook and print a corresponding message. It uses the <code>Type<\/code> property via the <code>api<\/code> interface.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance and workbook\napp = xw.apps.active\nwb = app.books.active\n\n# Iterate through all sheets in the workbook\nfor sheet in wb.sheets:\n    sheet_type = sheet.api.Type\n\nif sheet_type == -4167: # xlWorksheet\n    print(f\"Sheet '{sheet.name}' is a standard worksheet.\")\nelif sheet_type == -4109: # xlChart\n    print(f\"Sheet '{sheet.name}' is a chart sheet.\")\nelif sheet_type == 3: # xlExcel4MacroSheet\n    print(f\"Sheet '{sheet.name}' is an Excel 4 macro sheet.\")\nelif sheet_type == 4: # xlExcel4IntlMacroSheet\n    print(f\"Sheet '{sheet.name}' is an international macro sheet.\")\nelse:\n    print(f\"Sheet '{sheet.name}' has an unknown sheet type: {sheet_type}\")\n\n# Example to check a specific sheet's type\ntarget_sheet = wb.sheets&#91;'Sheet1']\nif target_sheet.api.Type == -4167:\n    print(f\"\\n'{target_sheet.name}' is confirmed to be a worksheet. Proceeding with data operations.\")\n    # Perform worksheet-specific tasks here, such as data manipulation\n    target_sheet.range('A1').value = 'Data Entry Point'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Type` member of the `Worksheet` object in the Excel object model represents the type of sheet, &#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-2354","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2354","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=2354"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2354\/revisions"}],"predecessor-version":[{"id":3588,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2354\/revisions\/3588"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}