{"id":2074,"date":"2026-05-20T16:17:03","date_gmt":"2026-05-20T08:17:03","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2074"},"modified":"2026-03-28T06:09:54","modified_gmt":"2026-03-28T06:09:54","slug":"how-to-use-applicationdefaultsheetdirection-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationdefaultsheetdirection-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.DefaultSheetDirection in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Application.DefaultSheetDirection<\/code> property in Excel&#8217;s object model allows developers to set or retrieve the default direction in which new worksheets are laid out within a workbook. This property influences whether the sheet content is displayed from left-to-right (typical for languages like English) or right-to-left (common for languages such as Arabic or Hebrew). It is particularly useful in internationalized applications where the user interface must adapt to different reading orientations. In xlwings, this property can be accessed and modified through the <code>api<\/code> property of the <code>App<\/code> object, providing a programmatic way to control sheet direction directly from Python.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app.api.DefaultSheetDirection<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This property is both readable and writable. It accepts integer values that correspond to specific direction settings:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>xlLTR<\/code> (value: <code>-5003<\/code>): Sets the default direction to left-to-right.<\/li>\n\n\n\n<li><code>xlRTL<\/code> (value: <code>-5004<\/code>): Sets the default direction to right-to-left.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These constants are part of the Excel enumeration <code>XlSheetDirection<\/code>. In xlwings, you can use the integer values directly or import the constants from the <code>win32com.client.constants<\/code> module if working on Windows with COM support, though xlwings typically abstracts this. The property applies at the application level, meaning it affects all new workbooks and sheets created during the session until changed.<\/p>\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>Reading the Current Default Sheet Direction:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False)\ncurrent_direction = app.api.DefaultSheetDirection\nprint(f\"Default sheet direction: {current_direction}\") # Output: -5003 for left-to-right\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This example retrieves the current setting, which defaults to left-to-right in most installations.<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Setting the Default Sheet Direction to Right-to-Left:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False)\napp.api.DefaultSheetDirection = -5004 # xlRTL for right-to-left\n# Create a new workbook to see the effect\nwb = app.books.add()\nws = wb.sheets&#91;0]\nprint(f\"New sheet direction set to: {app.api.DefaultSheetDirection}\")\nwb.save('right_to_left_sheet.xlsx')\napp.quit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After setting the property, any new worksheets will adopt the right-to-left layout, affecting text alignment and sheet navigation.<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Toggling Between Directions Based on User Input:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\ndef set_sheet_direction(direction='LTR'):\napp = xw.App(visible=False)\nif direction.upper() == 'RTL':\n    app.api.DefaultSheetDirection = -5004\nelse:\n    app.api.DefaultSheetDirection = -5003\n    wb = app.books.add()\n    print(f\"Sheet direction configured for {direction}.\")\napp.quit()\nset_sheet_direction('RTL')<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Application.DefaultSheetDirection` property in Excel&apos;s object model allows developers to set or&#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-2074","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2074","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=2074"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2074\/revisions"}],"predecessor-version":[{"id":3174,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2074\/revisions\/3174"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}