使用Ruby的win32ole库在.doc中插入图像 [英] insert image in .doc using win32ole library of Ruby

查看:191
本文介绍了使用Ruby的win32ole库在.doc中插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,我试图找到如何使用ruby Win32Ole api在MS Word(.doc文件)中插入图像。
我已经尝试了Range Object的函数InsertFile但看起来,它只是制作用于在我们的文件中插入其他doc文件。
有没有人知道任何与此相关的内容。这将非常有用。

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.

推荐答案

你可以通过调用 Document.InlineShapes.AddPicture()来做到这一点方法。

以下示例在第二句之前将图像插入到活动文档中。

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 )

文档可以在这里找到AddPicture()方法。

Documentation on the AddPicture() method can be found here.

上使用Ruby自动运行Word的附加细节,可以发现这里

Additional details on automating Word with Ruby can be found here.

David

这篇关于使用Ruby的win32ole库在.doc中插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆