1

I have an excel file and in one row there is an image in each cell. I'd like to give the cell like A2 to excel and wants to get back the image in this cell, but I don't get it. I figured out to use win32com instead of xlrd. This code is running, but it's not the code I need:

import win32com.client as win32
x = win32.Dispatch("Excel.Application")
wb = x.Workbooks.Open("Test.xlsx")
ws = wb.Sheets(1)
for i in ws.Shapes:
    print(i.TopLeftCell.Address)
wb.Close(True)

This code prints correctly each cells like A2, A3, A4,..., where an image is placed. So in general it recognizes an image. But how can I save a special image for example in cell A2? I tried something like

img = ws.Shapes(1).CopyPicture()

like shown here but it didn't work, img is empty.

It's not necessary to use win32com as long as it works, it seemed to be the right basic approach, but I'm open to alternative suggestions

1
  • was looking for the .Address to get the expected output out of TopLeftCell Commented Mar 23, 2022 at 6:08

1 Answer 1

0

you can try:

img = ws.Range("A1:B10").CopyPicture('1', '2')

like this, it worked for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.