Win32ole,从超链接而不是文本读取URL的方法? (Ruby,但不是必需的)

发布于 2024-10-08 10:33:15 字数 513 浏览 0 评论 0原文

我正在使用 WIN32OLE 来读取一些处于各种混乱状态的数据文件。现在,我已经能够使用句子和形状方法从大多数文件中读取文本,但是,对于带有超链接的文件,我只能读取超链接文本,而不能读取底层 URL。

我一直在挖掘“超链接”的方法/ole_methods,并尝试了很多,但没有一个发布了除文本之外的超链接的任何属性(在某些情况下,适当地如此)。

irb(主):084:0> doc.Sentences(4).hyperlinks.inspect
<代码> => “#

irb(main):085:0> doc.Sentences(4).hyperlinks.text
<代码> => “嗨,我是一个链接!”

最相关的 Google 结果涉及使用“地址”标签(不是超链接的方法)向 Excel 添加链接。其他人提到“行动”,这似乎也不是一种方法。

I'm working with WIN32OLE to read some data files in various states of disarray. I've been able to read text from the majority of the files now using the Sentences and Shapes methods, however, for files with hyperlinks I am only able to read the hyperlink text, not the underlying URL.

I've been digging through the methods/ole_methods of 'hyperlinks' and have tried many, but none have released any properties of the hyperlink other than the text (appropriately so, in some cases).

irb(main):084:0> doc.Sentences(4).hyperlinks.inspect
=> "#<WIN32OLE:0x2c233d0>"

irb(main):085:0> doc.Sentences(4).hyperlinks.text
=> "Hi I'm a link!"

The most relevant google results deal with adding links to Excel, using the 'address' tag which is not a method of hyperlinks. Others reference 'action', which also does not seem to be a method.

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

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

发布评论

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

评论(2

江湖彼岸 2024-10-15 10:33:15

这对我有用:

doc.Hyperlinks.each do |x|
  puts x.Address
end

编辑:我也用它来从文本框中获取链接。

doc.Shapes.each do |x|
  x.TextFrame.TextRange.Hyperlinks.each do |i|
    puts i.Address
  end
end

无论显示文本如何,这两者都会给出完整的地址。

This works for me:

doc.Hyperlinks.each do |x|
  puts x.Address
end

EDIT: I got this to work for grabbing the links out of TextBoxes too.

doc.Shapes.each do |x|
  x.TextFrame.TextRange.Hyperlinks.each do |i|
    puts i.Address
  end
end

Both of these give the full address, regardless of the display text.

白龙吟 2024-10-15 10:33:15

HyperLinks 对象是 HyperLink 对象的集合。

每个属性都包含一个应指向链接 URL 的“Address”属性和一个“textToDisplay”属性。

我对 ruby​​ 或 win32ole lib 一无所知,但是您可以获取集合中的超链接对象吗,也许像这样:

irb(main):084:0> doc.Sentences(4).hyperlinks(1).TextToDisplay

irb(main):084:0> doc.Sentences(4).hyperlinks(1).Address

The HyperLinks object is a collection of HyperLink objects.

Each one contains an "Address" property that should point to the URL of the link, and a "textToDisplay" property.

I don't know anything about ruby or the win32ole lib, but can you get to the Hyperlink objects in the collection, maybe like this:

irb(main):084:0> doc.Sentences(4).hyperlinks(1).TextToDisplay

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