Alex Zemtzov
Alex Zemtzov

Reputation: 17

Insert an object to excel by using python

I want to add some object to my excel sheet, I'm using openpyxl, In excel you do it by: Insert->Object

Is there a way to do it thru openpyxl or any other excel tool that working with python?

Upvotes: 0

Views: 2227

Answers (2)

Charlie Clark
Charlie Clark

Reputation: 19537

While this is not currently possible with openpyxl I suspect it would be fairly straightforward to add the relevant functionality using the add_image() method as a starting place.

Upvotes: 1

anonymous
anonymous

Reputation: 143

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.

Upvotes: 0

Related Questions