{"id":41,"date":"2026-02-07T11:47:36","date_gmt":"2026-02-07T03:47:36","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=41"},"modified":"2026-01-16T07:20:03","modified_gmt":"2026-01-16T07:20:03","slug":"how-to-resize-cells-and-images-using-openpyxl","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-resize-cells-and-images-using-openpyxl.html","title":{"rendered":"How To Resize Cells and Images Using OpenPyXL?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>ws.column_dimensions[&#8216;H&#8217;].width=18.0<\/p>\n<p>ws.row_dimensions[2].height=48.0<\/p>\n<p>\u00a0<\/p>\n<p>img=Image(img_file)<\/p>\n<p>img.width=46.0<\/p>\n<p>img.height=46.0<\/p>\n<p>ws.add_image(img,&#8217;H2&#8242;)\u00a0 #Add the image to cell H2<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Resize Cells and Images\n\nfrom openpyxl.drawing.image import Image\nfrom openpyxl import Workbook\n\n#Create a workbook\nwb=Workbook()\n#Get the active worksheet\nws=wb.active\n\n#Change the width and height of specified columns and rows\nws.column_dimensions&#91;'H'].width=18.0\nws.row_dimensions&#91;2].height=48.0\n\n#The picture file\nimg_file='pic.jpg'\n\n#Modify the image width and height\nimg=Image(img_file)\nimg.width=46.0\nimg.height=46.0\nws.add_image(img,'H2')  #Add the image to cell H2\n\nwb.save('image02.xlsx')\nwb.close()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"385\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/23.png\" alt=\"Resize Cells and Images Using OpenPyXL\" class=\"wp-image-293\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/23.png 872w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/23-300x132.png 300w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/23-768x339.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenPyXL<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-openpyxl-picture"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/41\/revisions\/294"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}