使用win32com.client在Excel中格式化图像 [英] Formatting Image in Excel using win32com.client

查看:484
本文介绍了使用win32com.client在Excel中格式化图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pythons win32com模块excel客户端创建一个excel电子表格。我想在excel电子表格报告中添加徽标。到目前为止,我已设法添加图片:

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?

推荐答案

尝试

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个位置。

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

关于帮助,我的参考是搜索excel interop,例如excel interop range或excel interop picture,这将导致图片对象文档

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

这篇关于使用win32com.client在Excel中格式化图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆