{"id":2114,"date":"2026-06-09T15:33:29","date_gmt":"2026-06-09T07:33:29","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2114"},"modified":"2026-03-28T07:14:31","modified_gmt":"2026-03-28T07:14:31","slug":"how-to-use-applicationfindformat-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationfindformat-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.FindFormat in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>FindFormat<\/code> property of the <code>Application<\/code> object in xlwings is a powerful feature for controlling the search criteria in Excel when using methods like <code>Find<\/code> or <code>Replace<\/code>. It allows you to define a set of formatting attributes (such as font color, cell fill, or number format) that Excel will use to locate cells matching that specific format. This is particularly useful for automating tasks where you need to find or modify cells based on their visual styling rather than their content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In xlwings, you access this property through the <code>Application<\/code> object. The <code>FindFormat<\/code> property itself returns a <code>FindFormat<\/code> object. You do not set it directly to a value; instead, you configure its properties (like <code>Font<\/code> or <code>Interior<\/code>) to define the search format. After setting these properties, any subsequent <code>Find<\/code> or <code>Replace<\/code> operation will use this format as a criterion if the <code>SearchFormat<\/code> argument is set to <code>True<\/code>.<\/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>import xlwings as xw\n\napp = xw.apps.active # Get the active Excel application\nfind_format = app.api.FindFormat # Access the FindFormat object<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have the <code>find_format<\/code> object, you can set its various properties. Common properties include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>find_format.Font.Color<\/code>: Sets the font color (e.g., <code>RGB(255, 0, 0)<\/code> for red).<\/li>\n\n\n\n<li><code>find_format.Interior.Color<\/code>: Sets the cell background color.<\/li>\n\n\n\n<li><code>find_format.Font.Bold<\/code>: Sets the font to bold (<code>True<\/code> or <code>False<\/code>).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">After configuring the format, you use it in a <code>Find<\/code> method. For example, to find the next cell with the specified format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>range_to_search = xw.books.active.sheets&#91;0].api.UsedRange\nfound_cell = range_to_search.Find(What=\"\", SearchFormat=True)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note: The <code>What<\/code> parameter is set to an empty string <code>\"\"<\/code> because we are searching by format only. The <code>SearchFormat=True<\/code> tells Excel to use the format defined in <code>FindFormat<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><br>Suppose you want to find all cells in a worksheet that have a yellow background. Here\u2019s how you can do it with xlwings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to Excel\napp = xw.apps.active\n\n# Define the search format: yellow interior\nfind_format = app.api.FindFormat\nfind_format.Interior.Color = 65535 # Yellow color in Excel's color index\n\n# Search in the used range of the first sheet\nsheet = xw.books.active.sheets&#91;0]\nsearch_range = sheet.api.UsedRange\nfirst_cell = search_range.Find(What=\"\", SearchFormat=True)\n\n# Loop to find all matching cells\nif first_cell:\n    addresses = &#91;first_cell.Address]\n    next_cell = search_range.FindNext(first_cell)\n    while next_cell.Address not in addresses:\n        addresses.append(next_cell.Address)\n        next_cell = search_range.FindNext(next_cell)\n        print(f\"Cells with yellow background: {addresses}\")\nelse:\n    print(\"No cells found with the specified format.\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `FindFormat` property of the `Application` object in xlwings is a powerful feature for controlli&#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-2114","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2114","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=2114"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2114\/revisions"}],"predecessor-version":[{"id":3235,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2114\/revisions\/3235"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}