0

I want to insert a Image(object) in MS-Excel Report which i am generating using openpyxl utility. Is there a way to do it using some python utility?

1 Answer 1

3

Openpyxl allows you to write images into your Excel files! Here it is in the official documentation.

import openpyxl

wb = openpyxl.Workbook()
ws = wb.worksheets[0]

picture = openpyxl.drawing.Image('/path/to/picture')
picture.anchor(ws.cell('cell to put the image'))
ws.add_image(picture)

wb.save('whatever you want to save the workbook as')

This code of course refers to creating a new workbook and adding the image into it. To add the image to your preexisting workbook you would obviously just load that workbook using load_workbook.

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

3 Comments

I am able to add the object using the code suggested by you. But i was looking for a code which can insert it as an attachment not as file as whole.
What do you mean by "attachment"? The OOXML specification expects all media files to be included in the package and this is what openpyxl does.
It's very clear : I want to insert an object and display it as an icon. I don't want to insert picture spanning several cells.

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.