How to use Application.SpellingOptions in the xlwings API way

The SpellingOptions member of the Application object in Excel provides a collection of settings that control how the spelling checker operates. These options are accessible through the xlwings library, allowing Python scripts to programmatically adjust spelling preferences, such as ignoring words in uppercase, flagging repeated words, or setting the language dictionary for proofing. This is particularly useful for automating document review processes, ensuring consistency in spell-checking behavior across multiple workbooks, or integrating custom spelling rules into data preparation workflows.

In xlwings, the SpellingOptions member is accessed via the api property of the Application object, which exposes the underlying Excel object model. The syntax for referencing it is straightforward: app.api.SpellingOptions, where app is an instance of the xlwings Application. This returns a SpellingOptions object with various properties that can be read or set. Most properties are Boolean values (True/False) or enumerations corresponding to Excel constants. For example, to check if the spelling checker ignores words in uppercase, you would use app.api.SpellingOptions.IgnoreUppercase. To modify it, assign a new value like app.api.SpellingOptions.IgnoreUppercase = True. Key properties include:

  • IgnoreUppercase: Ignores words in all uppercase letters.
  • IgnoreMixedDigits: Ignores words containing numbers.
  • SuggestMainOnly: Suggests only main dictionary entries.
  • GermanPostReform: Uses German post-reform spelling rules.
  • ArabicModes: Sets the Arabic spelling mode (e.g., for text validation).
    These properties map directly to Excel’s VBA SpellingOptions members, and their values can be retrieved or updated to customize spell-checking behavior.

For instance, to configure the spelling checker to ignore uppercase words and mixed digits, you could write:

import xlwings as xw
app = xw.App(visible=False) # Start Excel in background
app.api.SpellingOptions.IgnoreUppercase = True
app.api.SpellingOptions.IgnoreMixedDigits = True
print(f"Ignore uppercase: {app.api.SpellingOptions.IgnoreUppercase}")
app.quit() # Close the application

Another example involves setting language-specific options, such as enabling German post-reform rules:

import xlwings as xw
app = xw.App(visible=True)
app.api.SpellingOptions.GermanPostReform = True
# Perform a spell check on the active sheet
app.api.ActiveSheet.CheckSpelling()
app.quit()

Additionally, you can loop through all SpellingOptions properties to audit current settings:

import xlwings as xw
app = xw.App(visible=False)
options = app.api.SpellingOptions
for prop in ['IgnoreUppercase', 'IgnoreMixedDigits', 'SuggestMainOnly']:
    value = getattr(options, prop)
    print(f"{prop}: {value}")
app.quit()

July 20, 2026 (0)


Leave a Reply

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