简体   繁体   中英

Add image to excel worksheet using Interop and Iron Python

What is the best way to add images to an excel workbook using Iron Python and Interop only? I can't use any custom excel packages. I can get this method below using Shapes to work but its limited in image size to 100.

ws.Shapes.AddPicture(myimage, False, True, 415, 1, 100,100)

Can't seem to find any other Ironpy methods that work. Thanks!

I had to go back in time for this one big thanks to Konrad_K_Sobon
This is using Interop only, so it works in Iron Python without any addons like xlpy.

myimage = os.path.join(userdirectory,'file.png')
img = worksheet2.Pictures().Insert(myimage)
range = img.ShapeRange
range.LockAspectRatio = True
range.Width = 300
range.Height = 400 
img.Left = worksheet2.Cells[5,6].Left
img.Top = worksheet2.Cells[5,6].Top
img.Placement = 1
img.PrintObject = True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM