Class: Axlsx::Hyperlink

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/drawing/hyperlink.rb

Overview

Note:

using the hyperlink option when calling add_image on a drawing object is the recommended way to manage hyperlinks

a hyperlink object adds an action to an image when clicked so that when the image is clicked the link is fecthed.

See Also:

  • README

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Constructor Details

#initialize(parent, options = {}) {|_self| ... } ⇒ Hyperlink

Creates a hyperlink object parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent

Parameters:

  • parent (Pic)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • tooltip (String)

    message shown when hyperlinked object is hovered over with mouse.

  • tgtFrame (String)

    Target frame for opening hyperlink

  • invalidUrl (String)

    supposedly use to store the href when we know it is an invalid resource.

  • href (String)

    the target resource this hyperlink links to. This is actually stored on the relationship.

  • action (String)

    A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx

  • endSnd (Boolean)

    terminate any sound events when processing this link

  • history (Boolean)

    include this link in the list of visited links for the applications history.

  • highlightClick (Boolean)

    indicate that the link has already been visited.

Yields:

  • (_self)

Yield Parameters:


22
23
24
25
26
27
# File 'lib/axlsx/drawing/hyperlink.rb', line 22

def initialize(parent, options={})
  DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
  @parent = parent
  parse_options options
  yield self if block_given?
end

Instance Attribute Details

#actionString

An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx

Returns:

  • (String)

45
46
47
# File 'lib/axlsx/drawing/hyperlink.rb', line 45

def action
  @action
end

#end_sndBoolean Also known as: endSnd

Specifies if all sound events should be terminated when this link is clicked.

Returns:

  • (Boolean)

49
50
51
# File 'lib/axlsx/drawing/hyperlink.rb', line 49

def end_snd
  @end_snd
end

#highlight_clickBoolean Also known as: highlightClick

indicates that the link has already been clicked.

Returns:

  • (Boolean)

60
61
62
# File 'lib/axlsx/drawing/hyperlink.rb', line 60

def highlight_click
  @highlight_click
end

#historyBoolean

From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.

Returns:

  • (Boolean)

70
71
72
# File 'lib/axlsx/drawing/hyperlink.rb', line 70

def history
  @history
end

#hrefString

The destination of the hyperlink stored in the drawing's relationships document.

Returns:

  • (String)

33
34
35
# File 'lib/axlsx/drawing/hyperlink.rb', line 33

def href
  @href
end

#invalid_urlString Also known as: invalidUrl

The spec says: Specifies the URL when it has been determined by the generating application that the URL is invalid. That is the generating application can still store the URL but it is known that this URL is not correct.

What exactly that means is beyond me so if you ever use this, let me know!

Returns:

  • (String)

39
40
41
# File 'lib/axlsx/drawing/hyperlink.rb', line 39

def invalid_url
  @invalid_url
end

#tgt_frameString Also known as: tgtFrame

From the specs: Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened.

Returns:

  • (String)

78
79
80
# File 'lib/axlsx/drawing/hyperlink.rb', line 78

def tgt_frame
  @tgt_frame
end

#tooltipString

Text to show when you mouse over the hyperlink. If you do not set this, the href property will be shown.

Returns:

  • (String)

84
85
86
# File 'lib/axlsx/drawing/hyperlink.rb', line 84

def tooltip
  @tooltip
end

Instance Method Details

#relationshipRelationship

The relationship object for this hyperlink.

Returns:


88
89
90
# File 'lib/axlsx/drawing/hyperlink.rb', line 88

def relationship
  Relationship.new(self, HYPERLINK_R, href, :target_mode => :External)
end

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)

95
96
97
# File 'lib/axlsx/drawing/hyperlink.rb', line 95

def to_xml_string(str = '')
  serialized_tag 'a:hlinkClick', str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
end