{"id":2414,"date":"2026-11-06T16:53:22","date_gmt":"2026-11-06T08:53:22","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2414"},"modified":"2026-03-29T10:31:34","modified_gmt":"2026-03-29T10:31:34","slug":"how-to-use-rangeparse-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangeparse-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.Parse in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>Parse<\/code> method of the Range object in Excel is a powerful tool for breaking down text data within cells into separate columns, based on a specified delimiter or fixed-width format. This is particularly useful when dealing with imported or pasted data that is not properly structured across columns, such as addresses, full names, or log entries that are combined into a single cell. In xlwings, this functionality is accessible through the <code>api<\/code> property, which provides direct access to the underlying Excel object model, allowing for precise control over data parsing operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The primary purpose of the <code>Parse<\/code> method is to parse the text in a range of cells and distribute the parsed components into adjacent cells to the right. It can handle both delimiter-based parsing (like commas or tabs) and fixed-width parsing, depending on how the parse line is defined in Excel. This method effectively mimics the &#8220;Text to Columns&#8221; wizard in Excel&#8217;s UI but can be automated via code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax in xlwings:<\/strong><br>The method is called on a Range object through the <code>api<\/code> property. The basic syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>range.api.Parse(ParseLine, Destination)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ParseLine<\/strong>: A string that specifies how to parse the data. For delimiter parsing, it is a string containing the delimiter characters (e.g., <code>\",\"<\/code> for commas). For fixed-width parsing, it consists of numbers indicating column widths in characters, separated by spaces or commas (e.g., <code>\"5 10 15\"<\/code>). This parameter is optional; if omitted, Excel uses the default delimiter settings or the last used parse line.<\/li>\n\n\n\n<li><strong>Destination<\/strong>: A Range object specifying the top-left cell of the destination range where the parsed data will be placed. This parameter is optional; if omitted, parsing occurs in place, overwriting the original data with the parsed results in the same range.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Delimiter Parsing<\/strong>: Suppose cell A1 contains &#8220;John,Doe,30&#8221; and you want to split it into three columns based on commas.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\nwb = xw.Book.active()\nws = wb.sheets&#91;'Sheet1']\n# Parse the text in cell A1 using a comma delimiter\nws.range('A1').api.Parse(ParseLine=\",\")\n# After execution, A1 will contain \"John\", B1 will contain \"Doe\", and C1 will contain \"30\"<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Fixed-Width Parsing<\/strong>: If cell A2 has &#8220;2023-01-15LogEntry&#8221; with dates taking the first 10 characters and the log entry the rest, you can parse it by fixed widths.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code># Define fixed widths: first 10 characters for date, remaining for log\nws.range('A2').api.Parse(ParseLine=\"10\")\n# This will split \"2023-01-15\" into A2 and \"LogEntry\" into B2<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Parsing a Range with Destination<\/strong>: To parse data from column A and place the results starting at cell D1 to avoid overwriting original data.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>source_range = ws.range('A1:A5')\ndestination_range = ws.range('D1')\nsource_range.api.Parse(Destination=destination_range)\n# The parsed data from A1:A5 will be output starting at D1, extending across multiple columns as needed<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Parse` method of the Range object in Excel is a powerful tool for breaking down text data withi&#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-2414","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2414","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=2414"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2414\/revisions"}],"predecessor-version":[{"id":3670,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2414\/revisions\/3670"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}