How to insert images to specific excel file cells using python?

Viewed 874

I need to create an excel file and add images to certain cells so in each row I add two images in A1 and B1. I need to do this for around 150 images by copying and pasting them?

Can someone tell me how to do that using python script automatically by just defining the images path and the excel file path and the number of the images in the folder?

1 Answers

Using the xlsxwriter library

import xlsxwriter

# creates an excel sheet
workbook = xlsxwriter.Workbook('images.xlsx')
worksheet = workbook.add_worksheet()
worksheet.insert_image('B2', 'your-image-name.png')

workbook.close()

See the xlsxwriter docs for more details

Related