我正在创建一个excel电子表格使用pythons win32com模块excel客户端。我想添加一个徽标到我的excel电子表格报告。到目前为止,我已经成功地添加了这张图片:
# 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")我一直在浏览网络,我似乎无法找到一种方法来访问图片的位置属性以移动到特定的位置,也无法找到如何访问大小属性的方法。有没有一个帮助文档有一些我似乎找不到的例子?
发布于 2014-03-18 04:48:28
试一试
cell = sheet.Cells(1,1)
pic = sheet.Pictures().Insert(r"G:\logos\Logo.jpg")
pic.Left = cell.Left + 20
pic.Top = cell.Top + 30这将定位您的图片在20像素右和30从左上角的给定单元格。
关于帮助,我的参考是搜索"excel互操作“,如"excel互操作范围”或"excel互操作图片“,这将导致图片对象文档。
https://stackoverflow.com/questions/22464488
复制相似问题