{"id":2373,"date":"2026-10-17T07:35:41","date_gmt":"2026-10-16T23:35:41","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2373"},"modified":"2026-03-29T10:01:25","modified_gmt":"2026-03-29T10:01:25","slug":"how-to-use-rangecheckspelling-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangecheckspelling-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.CheckSpelling in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>CheckSpelling<\/code> member of the <code>Range<\/code> object in Excel is a method used to initiate a spell check on the text within a specified cell or range of cells. It mimics the functionality of the built-in spell checker in Excel, allowing developers to programmatically verify and correct spelling errors. This can be particularly useful in automating data validation processes, especially when dealing with user-generated content or imported text data that may contain typos or misspellings. The method returns a Boolean value indicating whether all words in the range are spelled correctly according to the dictionary settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings API:<\/strong><br>The xlwings library provides a Pythonic way to interact with Excel objects. To use <code>CheckSpelling<\/code> via xlwings, you typically access it through a <code>Range<\/code> object. The method&#8217;s signature in xlwings closely follows the Excel object model. The syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>range_object.api.CheckSpelling(CustomDictionary, IgnoreUppercase, AlwaysSuggest, SpellLang)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>range_object<\/code> is an xlwings <code>Range<\/code> object, such as <code>sheet.range('A1')<\/code> or <code>sheet.range('A1:B10')<\/code>.<\/li>\n\n\n\n<li><code>.api<\/code> is used to access the underlying Excel object model (e.g., the COM object in Windows or AppleScript object on Mac).<\/li>\n\n\n\n<li><code>CheckSpelling<\/code> is the method name.<\/li>\n\n\n\n<li>The parameters are optional and correspond to those in the Excel VBA <code>CheckSpelling<\/code> method. Their meanings and values are as follows:<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Parameter<\/th><th>Description<\/th><th>Typical Values<\/th><\/tr><\/thead><tbody><tr><td><code>CustomDictionary<\/code><\/td><td>A string specifying the filename of the custom dictionary to use. If omitted, the default dictionary is used.<\/td><td>e.g., <code>\"CUSTOM.DIC\"<\/code> or a path string.<\/td><\/tr><tr><td><code>IgnoreUppercase<\/code><\/td><td>A Boolean value. If <code>True<\/code>, words in all uppercase letters are ignored during spell check.<\/td><td><code>True<\/code> or <code>False<\/code> (default is <code>False<\/code>).<\/td><\/tr><tr><td><code>AlwaysSuggest<\/code><\/td><td>A Boolean value. If <code>True<\/code>, Excel will always suggest alternative spellings when a misspelling is found.<\/td><td><code>True<\/code> or <code>False<\/code> (default is <code>False<\/code>).<\/td><\/tr><tr><td><code>SpellLang<\/code><\/td><td>The language of the dictionary to use, specified by a language code.<\/td><td>e.g., <code>1033<\/code> for English (United States).<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example Usage:<\/strong><br>Below are practical xlwings code examples demonstrating how to use the <code>CheckSpelling<\/code> method in different scenarios.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Example 1: Basic spell check on a single cell.<\/em><br>This checks the spelling in cell A1 of the active sheet and prints whether all words are correct.<\/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\nsheet = wb.sheets.active\n\n# Define the range (single cell A1)\ntarget_range = sheet.range('A1')\n\n# Perform spell check with default settings\nis_correct = target_range.api.CheckSpelling()\nprint(f\"All words spelled correctly in A1: {is_correct}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Example 2: Spell check on a range with custom parameters.<\/em><br>This checks a range from A1 to B5, ignoring uppercase words and using a specific custom dictionary.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\napp = xw.apps.active\nwb = app.books.active\nsheet = wb.sheets.active\n\n# Define a larger range\ntarget_range = sheet.range('A1:B5')\n\n# Perform spell check, ignoring uppercase words and specifying a custom dictionary\nis_correct = target_range.api.CheckSpelling(CustomDictionary=\"MyCustom.dic\", IgnoreUppercase=True)\nif not is_correct:\n    print(\"Spelling errors found in range A1:B5. Consider reviewing manually.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Example 3: Iterating through a column to check spelling in each cell.<\/em><br>This loops through cells in column A (rows 1 to 10) and marks cells with spelling errors by changing the font color to red.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nfrom xlwings import constants\n\napp = xw.apps.active\nwb = app.books.active\nsheet = wb.sheets.active\n\nfor i in range(1, 11):\n    cell = sheet.range(f'A{i}')\n    # Check spelling for each cell\n    is_correct = cell.api.CheckSpelling()\n    if not is_correct:\n        # Highlight misspelled cells in red\n        cell.api.Font.Color = constants.RgbColor.rgbRed\n        print(f\"Spelling error detected in cell A{i}\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `CheckSpelling` member of the `Range` object in Excel is a method used to initiate a spell check&#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-2373","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2373","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=2373"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2373\/revisions"}],"predecessor-version":[{"id":3615,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2373\/revisions\/3615"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}