As the Title suggests, i am trying to find how to insert image in MS Word(.doc file) using ruby Win32Ole api.
I have tried the function InsertFile of Range Object but it seems, it is only made for inserting other doc file in our file in question.
Does anyone know anything related to this . It will very helpful.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can do this by calling the Document.InlineShapes.AddPicture()
method.
The following example inserts an image into the active document, before the second sentence.
require 'win32ole'
word = WIN32OLE.connect('Word.Application')
doc = word.ActiveDocument
image = 'C:\MyImage.jpg'
range = doc.Sentences(2)
params = { 'FileName' => image, 'LinkToFile' => false,
'SaveWithDocument' => true, 'Range' => range }
pic = doc.InlineShapes.AddPicture( params )
Documentation on the AddPicture() method can be found here.
Additional details on automating Word with Ruby can be found here.
David