{"id":2383,"date":"2026-10-22T07:51:04","date_gmt":"2026-10-21T23:51:04","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2383"},"modified":"2026-03-29T10:07:15","modified_gmt":"2026-03-29T10:07:15","slug":"how-to-use-rangeconverttolinkeddatatype-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-rangeconverttolinkeddatatype-in-the-xlwings-api-way\/","title":{"rendered":"How to use Range.ConvertToLinkedDataType in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <strong>ConvertToLinkedDataType<\/strong> method in Excel, accessible through the <code>xlwings<\/code> API, is a powerful feature for converting static data in a range into dynamic linked data types. This functionality is particularly useful when working with data types like Stocks or Geography, where Excel can pull real-time or updated information from online sources. By converting a range to a linked data type, you enable automatic data refresh and access to rich, structured data fields without manual updates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In <code>xlwings<\/code>, this method is called on a <code>Range<\/code> object. The syntax is straightforward: <code>range_object.api.ConvertToLinkedDataType(ServiceID, LanguageCulture)<\/code>. Here, <code>range_object<\/code> refers to the Excel range you want to convert, typically selected using <code>xlwings<\/code> methods like <code>sheet.range()<\/code> or <code>app.range()<\/code>. The <code>api<\/code> property grants access to the underlying Excel object model, allowing direct use of Excel VBA-equivalent methods. The method takes two parameters: <code>ServiceID<\/code> and <code>LanguageCulture<\/code>. <code>ServiceID<\/code> is an optional parameter that specifies the linked data service to use; for example, use <code>\"Finance\"<\/code> for stock data or <code>\"Geography\"<\/code> for geographic information. If omitted, Excel will attempt to auto-detect the service based on the data content. <code>LanguageCulture<\/code> is also optional and sets the language and culture for the data, such as <code>\"en-US\"<\/code> for English (United States). If not provided, it defaults to the application&#8217;s current language settings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, suppose you have a list of company ticker symbols in cells A1:A5 of an Excel worksheet, and you want to convert them to linked stock data types to fetch real-time financial information. Using <code>xlwings<\/code>, you can achieve this with a few lines of Python code. First, ensure <code>xlwings<\/code> is installed and import it. Then, connect to Excel, specify the target range, and call <code>ConvertToLinkedDataType<\/code>. Below is a code snippet demonstrating this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to the active Excel instance or open a workbook\napp = xw.apps.active\nwb = app.books.active\nsheet = wb.sheets&#91;'Sheet1']\n\n# Define the range containing ticker symbols (e.g., \"MSFT\", \"AAPL\")\ntarget_range = sheet.range('A1:A5')\n\n# Convert the range to linked data type for stocks\ntarget_range.api.ConvertToLinkedDataType(ServiceID=\"Finance\", LanguageCulture=\"en-US\")\n\n# Save and close if needed\nwb.save()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The **ConvertToLinkedDataType** method in Excel, accessible through the `xlwings` API, is a powerful&#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-2383","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2383","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=2383"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2383\/revisions"}],"predecessor-version":[{"id":3629,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2383\/revisions\/3629"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}