Skip to content

Instantly share code, notes, and snippets.

@mujeebishaque
Created April 1, 2020 11:02
Show Gist options
  • Save mujeebishaque/eede0dd9cd10c5813b630a04e3362fb9 to your computer and use it in GitHub Desktop.
Save mujeebishaque/eede0dd9cd10c5813b630a04e3362fb9 to your computer and use it in GitHub Desktop.
add multiple images using openpyxl
def real_writer(self, folder_name=None, images=None):
if images is None or len(images) ==0:
return
import openpyxl
from openpyxl.drawing.image import Image
workbook = openpyxl.Workbook()
# Let's use the hello_world spreadsheet since it has less data
# workbook = load_workbook(filename="hello_world.xlsx")
sheet = workbook.active
count = 0
for image in images:
proto_image = Image(str(image))
# A bit of resizing to not fill the whole spreadsheet with the logo
proto_image.height = 250
proto_image.width = 300
sheet.add_image(proto_image, "A3" if count == 0 else "F3")
count += 1
workbook.save(self.FOLDER_PATH/"output.xlsx")
@hrun04
Copy link

hrun04 commented Jun 6, 2021

I am new with python, how do I use ur function ? I kept on failing

@vispar-tech
Copy link

vispar-tech commented May 15, 2023

I am new with python, how do I use ur function ? I kept on failing

This not a function, it`s a class method. You need to use it inside a class, like below

Class MyExcel(openpyxl.Workbook):
# your additional functions inside id


wb = MyExcel()

# wb.real_writer()
# wb.my_method()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment