{"id":40,"date":"2026-02-06T17:13:55","date_gmt":"2026-02-06T09:13:55","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=40"},"modified":"2026-01-16T07:17:53","modified_gmt":"2026-01-16T07:17:53","slug":"how-to-insert-a-picture-using-openpyxl","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-insert-a-picture-using-openpyxl.html","title":{"rendered":"How To Insert a Picture Using OpenPyXL?"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">from openpyxl.drawing.image import Image<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">img_file=&#8217;pic.jpg&#8217;<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">img=Image(img_file)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">ws.add_image(img,&#8217;A1&#8242;)<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Add Images to the Worksheet\n\n#Import relevant classes\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#Open an image file\nimg_file='pic.jpg'\n#Create an Image object from the image\nimg=Image(img_file)\n#Add the Image object to cell A1\nws.add_image(img,'A1')\n\nwb.save('image01.xlsx')\nwb.close()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"717\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/22.png\" alt=\"Insert a Picture Using OpenPyXL\" class=\"wp-image-290\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/22.png 872w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/22-300x247.png 300w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/22-768x631.png 768w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\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-40","post","type-post","status-publish","format-standard","hentry","category-openpyxl-picture"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/40","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=40"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":291,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions\/291"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}