使用Ruby的win32ole库在.doc中插入图像

发布于 2024-08-02 09:32:26 字数 161 浏览 3 评论 0原文

正如标题所示,我正在尝试找到如何使用 ruby​​ Win32Ole api 在 MS Word(.doc 文件)中插入图像。
我尝试过 Range 对象的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来世叙缘 2024-08-09 09:32:26

您可以通过调用 Document.InlineShapes.AddPicture() 方法来完成此操作。

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

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() 方法的文档可以在此处找到。

有关使用 Ruby 自动化 Word 的更多详细信息,请访问此处

大卫

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文