Created
April 1, 2020 11:02
-
-
Save mujeebishaque/eede0dd9cd10c5813b630a04e3362fb9 to your computer and use it in GitHub Desktop.
add multiple images using openpyxl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
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
I am new with python, how do I use ur function ? I kept on failing