python完成以下需求import pythoncompythoncomCoInitializefrom win32comclient import Dispatchimport win32comclient filename = DBook1xlsx xlApp = DispatchExcelApplicationxlAppVisible = True #显式打开excel 调试设置True
import pythoncom pythoncom.CoInitialize() from win32com.client import Dispatch import win32com.client
filename = "D:\Book1.xlsx" xlApp = Dispatch('Excel.Application') xlApp.Visible = True book = xlApp.Workbooks.Add() xlSheet = book.Worksheets(1) xlSheet.Cells(1,1).Value = 'title' xlSheet.Cells(2,1).Value = 123 shape = xlSheet.Shapes.AddOLEObject(ClassType='Paint.Picture',Filename="D:\union.jpeg", Link=False) shape.Left = xlSheet.Cells(2,2).Left shape.Top = xlSheet.Cells(2,2).Top xlSheet.Rows(2).RowHeight = shape.Height xlSheet.Columns(2).ColumnWidth = shape.Width
xlSheet.Shapes.AddPicture("D:\A.png", LinkToFile=False, SaveWithDocument=True, Left=xlSheet.Cells(8, 8).Left, Top=xlSheet.Cells(8, 8).Top, Width=-1, Height=-1)
book.SaveAs(filename
原文地址: https://www.cveoy.top/t/topic/iN5a 著作权归作者所有。请勿转载和采集!