{"id":92,"date":"2026-03-02T11:17:28","date_gmt":"2026-03-02T03:17:28","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=92"},"modified":"2026-01-17T11:09:12","modified_gmt":"2026-01-17T11:09:12","slug":"how-to-add-image-in-the-worksheet-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-add-image-in-the-worksheet-using-xlwings\/","title":{"rendered":"How To Add Image In the Worksheet Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Use the `AddPicture` method of the `Shape` object to create an image from an existing file. This method returns a `Shape` object representing the new image. The syntax of this method is:<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; margin-left: .375in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">sht.api.Shapes.AddPicture(FileName,LinkToFile,SaveWithDocument,Left,Top,Width,Height)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Here, `sht` represents the worksheet, and the parameters are as follows:<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<div style=\"direction: ltr;\">\n<table style=\"direction: ltr; border-collapse: collapse; border: 1pt solid #A3A3A3;\" title=\"\" border=\"1\" summary=\"\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"vertical-align: top; width: 1.2652in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt; text-align: center;\">Name<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.9597in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt; text-align: center;\">Required\/Optional<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.3402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt; text-align: center;\">Data Type<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 4.8569in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt; text-align: center;\">Description<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top; width: 1.2652in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">FileName<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.9402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Required<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.3402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">String<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 4.7451in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">The image file name<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top; width: 1.2652in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">LinkToFile<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.9402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Required<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.3548in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">MsoTriState<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 4.8569in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Set to `False` to make the image an independent copy, not linked. Set to `True` to link the image to the file from which it was created<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top; width: 1.2652in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">SaveWithDocument<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.9402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Required<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.3548in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">MsoTriState<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 4.8569in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Saves the image with the document. Use `False` to store only the link information, and `True` to save the linked image with the document. This parameter must be `True` if `LinkToFile` is `False`<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top; width: 1.2652in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Left<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.9402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Required<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.3402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Single<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 4.8569in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">The position of the top-left corner of the image relative to the document&#8217;s top-left corner (in points)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top; width: 1.2652in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Top<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.9402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Required<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.3402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Single<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 4.8569in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">The position of the top-left corner of the image relative to the document&#8217;s top (in points)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top; width: 1.2652in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Width<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.9402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Required<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.3402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Single<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 4.8569in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">The width of the image in points (enter `-1` to retain the original width)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top; width: 1.2652in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Height<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.9402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Required<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 1.3402in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">Single<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 4.8569in; padding: 4pt 4pt 4pt 4pt; border: 1pt solid #A3A3A3;\">\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">The height of the image in points (enter `-1` to retain the original height)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">sht.api.Shapes.AddPicture(root+&#8221;\/picpy.jpg&#8221;, True, True, 100, 50, 100, 100)<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Add Picture\n\nimport xlwings as xw    #Import xlwings package\nimport os\n\nroot = os.getcwd()\napp=xw.App()\nbk=app.books.active   #Get the active workbook\nsht=bk.sheets.active    #Get the active worksheet\n\nsht.api.Shapes.AddPicture(r\"D:\\picpy.jpg\", True, True, 100, 50, 100, 100)\n\n#bk.save()\n#bk.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"782\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-2.png\" alt=\"Add Image In the Worksheet Using xlwings\" class=\"wp-image-463\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-2.png 782w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-2-300x185.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/image-2-768x473.png 768w\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-xlwings-shape"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/92","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=92"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":464,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/92\/revisions\/464"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}