Formatting Image in Excel using win32com.client

余生颓废 提交于 2020-01-06 14:43:29

问题


I am creating an excel spreadsheet using pythons win32com module excel client. I wanted to add a logo to my excel spreadsheet report. So far I have managed to add the picture:

# Set a variable to an empty excel instance
excel = win32com.client.Dispatch("Excel.Application")

# Initialize a workbook within excel
book = excel.Workbooks.Add()

# Create sheet in book
sheet = book.Worksheets(1)

sheet.Pictures().Insert(r"G:\logos\Logo.jpg")

I've been pouring through the web and I cannot seem to find a way to access the position properties of the picture to move to it a particular place, nor can I find out how to access the sizing properties. Is there a help doc out there that has some examples that I cannot seem to find?


回答1:


Try

cell = sheet.Cells(1,1)
pic = sheet.Pictures().Insert(r"G:\logos\Logo.jpg")
pic.Left = cell.Left + 20
pic.Top = cell.Top + 30

which will position your picture at 20 pixels right and 30 down from top left corner of given cell.

Regarding help, my reference is search for "excel interop " such as "excel interop range" or "excel interop picture" which leads to Picture object docs.



来源:https://stackoverflow.com/questions/22464488/formatting-image-in-excel-using-win32com-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!