Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top