How to use Application.UseSystemSeparators in the xlwings API way

The Application.UseSystemSeparators property in Excel is a Boolean value that controls whether Excel uses the system’s decimal and thousands separators for number formatting, or the separators specified in the Windows regional settings for the Excel application itself. When set to True (the default), Excel will use the separators defined by the operating system’s regional settings (e.g., a period for decimal and a comma for thousands in the US locale). When set to False, Excel will use the alternative separators, which are typically a comma for decimal and a period for thousands, as might be used in some European locales. This property is crucial for ensuring data is displayed and interpreted correctly in international environments, especially when workbooks are shared across different regional systems.

In the xlwings API, this property is accessed through the Application object. The syntax for getting or setting the property is straightforward:

import xlwings as xw

app = xw.apps.active # or xw.App() for a new instance

# Get the current value
current_setting = app.api.UseSystemSeparators

# Set the value
app.api.UseSystemSeparators = False # Use alternative separators

Here, app.api provides direct access to the underlying Excel Application object from the COM interface. The UseSystemSeparators property is a read/write Boolean. No parameters are required for getting or setting it. To determine the system’s current separators, you can check the Application.DecimalSeparator and Application.ThousandsSeparator properties, which are influenced by this setting.

Example use cases include preparing a workbook for users in a locale with different formatting norms or ensuring consistent number parsing in automated scripts. Below is a practical xlwings code example that demonstrates toggling this property and observing the effect on cell formatting:

import xlwings as xw

# Connect to the active Excel instance
app = xw.apps.active

# Display initial state
print(f"Initial UseSystemSeparators: {app.api.UseSystemSeparators}")
print(f"Decimal Separator: {app.api.DecimalSeparator}")
print(f"Thousands Separator: {app.api.ThousandsSeparator}")

# Change to alternative separators
app.api.UseSystemSeparators = False
print(f"\nAfter setting to False:")
print(f"Decimal Separator: {app.api.DecimalSeparator}")
print(f"Thousands Separator: {app.api.ThousandsSeparator}")

# Write a sample number to a cell to see formatting
wb = app.books.active
ws = wb.sheets[0]
ws.range('A1').value = 12345.67
ws.range('A1').number_format = '#,##0.00'

# The display in Excel will reflect the current separators.
# For example, with UseSystemSeparators=False, it might show as "12.345,67" depending on system settings.

# Revert to system separators
app.api.UseSystemSeparators = True
print(f"\nReverted to True:")
print(f"Decimal Separator: {app.api.DecimalSeparator}")
print(f"Thousands Separator: {app.api.ThousandsSeparator}")

# Save and close
wb.save()
app.quit()

July 30, 2026 (0)


Leave a Reply

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