简体   繁体   English

如何使用Python win32com将图片保存到文档

[英]How to save pictures to document with Python win32com

I am making html to doc converter 我正在将html转换为doc转换器

from win32com.client import Dispatch 从win32com.client导入调度
wrd=Dispatch('Word.Application') wrd = Dispatch('Word.Application')
doc=wrd.Documents.Open(inputfile) doc = wrd.Documents.Open(输入文件)
doc.SaveAs(outputfile, FileFormat=0) doc.SaveAs(outputfile,FileFormat = 0)
doc.Close doc。关闭

And I wand save picture to document: Prepare->Edit links to file->Save picture to document 然后我将图片保存到文档:准备->编辑链接到文件->将图片保存到文档

What command I need? 我需要什么命令?

http://i.stack.imgur.com/SJOS7.png http://i.stack.imgur.com/SJOS7.png

I believe you are looking for the AddPicture method in the InlineShapes collection. 我相信您正在InlineShapes集合中寻找AddPicture方法。

 FileName 

Required String. 必需的字符串。 The path and file name of the picture. 图片的路径和文件名。

 LinkToFile 

Optional Object. 可选对象。 True to link the picture to the file from which it was created. 将图片链接到创建图片的文件时为True。 False to make the picture an independent copy of the file. 将图片设为文件的独立副本为False。 The default value is False. 默认值为False。

 **SaveWithDocument** 

Optional Object. 可选对象。 True to save the linked picture with the document. 如果为True,则将链接的图片与文档一起保存。 The default value is False. 默认值为False。

 Range 

Optional Object. 可选对象。 The location where the picture will be placed in the text. 图片将在文本中放置的位置。 If the range isn't collapsed, the picture replaces the range; 如果范围未缩小,则图片将替换该范围; otherwise, the picture is inserted. 否则,将插入图片。 If this argument is omitted, the picture is placed automatically. 如果省略此参数,则将自动放置图片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM