How to use Worksheet.DisplayRightToLeft in the xlwings API way

The DisplayRightToLeft property of a Worksheet object in Excel is a Boolean property that controls the reading order and layout direction of the worksheet. When set to True, the worksheet is displayed in a right-to-left orientation, which is particularly useful for languages that are written from right to left, such as Arabic, Hebrew, or Farsi. This setting affects the alignment of text, the order of columns (with column A appearing on the right side), and the direction of scrolling. When set to False (the default), the worksheet uses the standard left-to-right orientation. In xlwings, this property can be accessed and modified directly through the api property of a Worksheet object, which provides access to the underlying Excel object model.

Syntax in xlwings:
The property is accessed via the api property of a Worksheet object. The syntax is:

worksheet.api.DisplayRightToLeft

This property is both readable and writable. It accepts and returns a Boolean value:

  • True: Enables right-to-left display.
  • False: Disables right-to-left display (left-to-right default).

Parameters:
This property does not take any parameters. It is a simple Boolean attribute.

Example Usage:
Below are xlwings code examples demonstrating how to get and set the DisplayRightToLeft property.

  1. Getting the current DisplayRightToLeft setting:
import xlwings as xw

# Open an existing workbook or create a new one
wb = xw.Book('example.xlsx')
sheet = wb.sheets['Sheet1']

# Get the current DisplayRightToLeft value
current_setting = sheet.api.DisplayRightToLeft
print(f"Current DisplayRightToLeft setting: {current_setting}")
  1. Setting DisplayRightToLeft to True (right-to-left orientation):
import xlwings as xw

# Open an existing workbook
wb = xw.Book('example.xlsx')
sheet = wb.sheets['Sheet1']

# Set the worksheet to display right-to-left
sheet.api.DisplayRightToLeft = True
print("Worksheet is now set to right-to-left display.")
  1. Toggling the DisplayRightToLeft setting:
import xlwings as xw

# Open an existing workbook
wb = xw.Book('example.xlsx')
sheet = wb.sheets['Sheet1']

# Toggle the current setting
sheet.api.DisplayRightToLeft = not sheet.api.DisplayRightToLeft
new_setting = sheet.api.DisplayRightToLeft
print(f"Toggled DisplayRightToLeft to: {new_setting}")
  1. Applying DisplayRightToLeft to multiple worksheets:
import xlwings as xw

# Open an existing workbook
wb = xw.Book('example.xlsx')

# Loop through all worksheets and set them to right-to-left display
for sheet in wb.sheets:
    sheet.api.DisplayRightToLeft = True
    print(f"Set {sheet.name} to right-to-left display.")

September 19, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *