May-03-2023, 06:48 AM
(May-02-2023, 08:09 AM)buran Wrote:(May-02-2023, 01:43 AM)cools0607 Wrote: failed to get the proper image size from the cell border.What exactly does it mean to get image size from cell border?
Also, please include your code (minimal reproducible example)
I attached my code below
import openpyxl from openpyxl.drawing.image import Image fn = "SS1.xlsx" wb = openpyxl.load_workbook(fn) ws = wb['AA'] cell='B2' #insert img to B2 cell # get cell size width = ws.column_dimensions['2'].width height = ws.row_dimensions[2].height img = Image("my_img.jpg") # build img img.width = width # chamge img width same as cell's width img.height = height # chamge img height same as cell's height ws.add_image(img,cell) # insert img to B2 wb.save('out.xlsx') #save fileadd attchements (py code/ image/ excel)
Attached Files
openpyxl.zip (Size: 55.86 KB / Downloads: 51)