{"id":1975,"date":"2026-04-01T07:36:55","date_gmt":"2026-03-31T23:36:55","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=1975"},"modified":"2026-03-28T03:42:15","modified_gmt":"2026-03-28T03:42:15","slug":"how-to-use-applicationcentimeterstopoints-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-applicationcentimeterstopoints-in-the-xlwings-api-way\/","title":{"rendered":"How to use Application.CentimetersToPoints in the xlwings API way"},"content":{"rendered":"\n<p>The <code>Application.CentimetersToPoints<\/code> method in Excel&#8217;s object model is a utility function that converts a measurement from centimeters to points. In the context of xlwings, which provides a Pythonic interface to automate Excel, this method is accessible through the <code>Application<\/code> object. It is particularly useful when you need to set dimensions, such as row heights, column widths, or shape sizes, in points\u2014Excel&#8217;s native unit for such measurements\u2014while working with centimeter-based data. This conversion ensures precision and consistency in layout and formatting tasks, especially in international settings where centimeters are a common metric unit.<\/p>\n\n\n\n<p><strong>Syntax in xlwings:<\/strong><br>In xlwings, you call this method via the <code>app<\/code> object, which represents the Excel application. The syntax is:<br><code>app.api.CentimetersToPoints(Centimeters)<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Centimeters<\/code>: Required. A numeric value or expression representing the length in centimeters that you want to convert to points. This parameter can be a single number, a variable, or a calculated result.<br>The method returns a <code>Single<\/code> (floating-point) value representing the equivalent measurement in points. Note that 1 centimeter is approximately equal to 28.3465 points in Excel, as points are defined as 1\/72 of an inch, and 1 inch equals 2.54 centimeters.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example Usage with xlwings:<\/strong><br>Below are practical examples demonstrating how to use <code>CentimetersToPoints<\/code> in xlwings for various Excel automation tasks. These examples assume you have an Excel application instance running via xlwings.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Converting a Single Measurement:<\/strong><br>This example converts 5 centimeters to points and prints the result. It is useful for quick calculations or debugging.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False) # Start Excel in the background\npoints_value = app.api.CentimetersToPoints(5)\nprint(f\"5 cm is equal to {points_value} points.\") # Output: ~141.7325 points\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Setting Column Width Based on Centimeters:<\/strong><br>Here, we set the width of column A in the active workbook to a specific centimeter value by converting it to points. Excel&#8217;s column width is measured in points (or character units, but points are used for precise control via API).<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=True)\nwb = app.books.active\nws = wb.sheets&#91;0]\n# Convert 3.5 cm to points and set as column width for column A\nwidth_in_points = app.api.CentimetersToPoints(3.5)\nws.api.Columns(\"A\").ColumnWidth = width_in_points\nwb.save()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Adjusting Row Height Dynamically:<\/strong><br>This example uses a loop to set row heights for multiple rows based on a list of centimeter values. It showcases how to integrate the conversion into batch operations.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=False)\nwb = app.books.add()\nws = wb.sheets&#91;0]\ncm_heights = &#91;2.0, 2.5, 3.0] # Heights in centimeters for rows 1 to 3\nfor i, cm in enumerate(cm_heights, start=1):\npoints_height = app.api.CentimetersToPoints(cm)\nws.api.Rows(i).RowHeight = points_height\nwb.save(\"adjusted_heights.xlsx\")\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Calculating Shape Dimensions:<\/strong><br>When adding or resizing shapes, you might need to specify sizes in points. This example creates a rectangle with width and height derived from centimeter measurements.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\napp = xw.App(visible=True)\nwb = app.books.active\nws = wb.sheets&#91;0]\n# Define dimensions in centimeters\nwidth_cm, height_cm = 4.0, 2.0\nwidth_pts = app.api.CentimetersToPoints(width_cm)\nheight_pts = app.api.CentimetersToPoints(height_cm)\n# Add a rectangle shape at position (100, 100) with converted dimensions\nshape = ws.shapes.add_shape(\n1, # Type: rectangle\n100, 100, # Left and top positions in points\nwidth_pts, height_pts\n)\nshape.name = \"MetricRectangle\"\nwb.save()\napp.quit()<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `Application.CentimetersToPoints` method in Excel&apos;s object model is a utility function that conv&#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-1975","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/1975","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=1975"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/1975\/revisions"}],"predecessor-version":[{"id":3007,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/1975\/revisions\/3007"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=1975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=1975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=1975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}