向 Word 文件中插入图片
向 Word 文件插入图片的语法为:
例如,在 cl ip graph.docx 文件的第 4 段插入 ce ll.jpg 图片,井将图片文件保存于
Word 文件内:
import os from win32com import client word = client.gencache.EnsureDispatch(‘Word.Application‘) word.Visible = 1 word.DisplayAlerts = 0 # cpath=os.path.dirname(__file__) doc = word.Documents.Open("F:\\pythonBase\\pythonex\\ch08\\media\\clipgraph.docx") paragraphs = doc.Paragraphs range1 = paragraphs(4).Range range1.InlineShapes.AddPicture("F:\\pythonBase\\pythonex\\ch08\\media\\cell.jpg", False, True) #doc.Close() #word.Quit()
吴裕雄--天生自然python学习笔记:python文档操作插入图片
原文:https://www.cnblogs.com/tszr/p/12030068.html