def t_barcode():
file = r'e:\code\dock_project\DN--SHIPSHIP.xls'
pythoncom.CoInitialize()
xl = win32com.client.Dispatch("Excel.Application")
xl.DisplayAlerts = False
xl.Visible = True
wb = xl.Workbooks.Open(file)
sheets = wb.Worksheets('P1')
a = sheets.Range("H10")
pic = sheets.Pictures().Insert(r'D:\code\t_rfc\resized_image.jpg')
pic.Left = a.Left + 20 #相对于单元格 a 的 位置
pic.Top = a.Top + 20
pic.Width = 100 #设置宽度,能起作用
为什么不用原生python模块,因为需要保持excel原有格式