Class: Axlsx::WorksheetHyperlink

Inherits:
Object
  • Object
show all
Includes:
Accessors, OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb

Overview

A worksheet hyperlink object. Note that this is not the same as a drawing hyperlink object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

included, #serialized_attributes

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(worksheet, options = {}) {|_self| ... } ⇒ WorksheetHyperlink

Note:

the preferred way to add hyperlinks to your worksheet is the Worksheet#add_hyperlink method

Creates a new hyperlink object.

Parameters:

  • worksheet (Worksheet)

    the Worksheet that owns this hyperlink

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

    options to use when creating this hyperlink

  • [String] (Hash)

    a customizable set of options

  • [Symbol] (Hash)

    a customizable set of options

  • [String|Cell] (Hash)

    a customizable set of options

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 18

def initialize(worksheet, options={})
  DataTypeValidator.validate "Hyperlink.worksheet", [Worksheet], worksheet
  @worksheet = worksheet
  @target = :external
  parse_options options
  yield self if block_given?
end

Instance Attribute Details

#refString

Cell location of hyperlink on worksheet.

Returns:

  • (String)


32
33
34
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 32

def ref
  @ref
end

Instance Method Details

#idString

The id of the relationship for this object

Returns:

  • (String)


57
58
59
60
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 57

def id
  return unless @target == :external
  "rId#{(@worksheet.relationships_index_of(self)+1)}"
end

#location_or_idHash

The values to be used in serialization based on the target. location should only be specified for non-external targets. r:id should only be specified for external targets.

Returns:

  • (Hash)


75
76
77
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 75

def location_or_id
  @target == :external ?  { :"r:id" => id } : { :location => location }
end

#relationshipRelationship

Returns:



50
51
52
53
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 50

def relationship
  return unless @target == :external
  Relationship.new HYPERLINK_R, location, :target_mode => :External
end

#target=(target) ⇒ Object

Sets the target for this hyperlink. Anything other than :external instructs the library to treat the location as an in-workbook reference.

Parameters:

  • target (Symbol)


36
37
38
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 36

def target=(target)
  @target = target
end

#to_xml_string(str = '') ⇒ String

Seralize the object

Parameters:

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

Returns:

  • (String)


65
66
67
68
69
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 65

def to_xml_string(str='')
  str << '<hyperlink '
  serialized_attributes str, location_or_id
  str << '/>'
end