Class: Axlsx::WorksheetHyperlink
- Inherits:
-
Object
- Object
- Axlsx::WorksheetHyperlink
- 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
-
#ref ⇒ String
Cell location of hyperlink on worksheet.
Instance Method Summary collapse
-
#id ⇒ String
The id of the relationship for this object.
-
#initialize(worksheet, options = {}) {|_self| ... } ⇒ WorksheetHyperlink
constructor
Creates a new hyperlink object.
-
#location_or_id ⇒ Hash
The values to be used in serialization based on the target.
- #relationship ⇒ Relationship
-
#target=(target) ⇒ Object
Sets the target for this hyperlink.
-
#to_xml_string(str = '') ⇒ String
Seralize the object.
Methods included from SerializedAttributes
included, #serialized_attributes, #serialized_element_attributes
Methods included from OptionsParser
Constructor Details
#initialize(worksheet, options = {}) {|_self| ... } ⇒ WorksheetHyperlink
the preferred way to add hyperlinks to your worksheet is the Worksheet#add_hyperlink method
Creates a new hyperlink object.
18 19 20 21 22 23 24 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 18 def initialize(worksheet, ={}) DataTypeValidator.validate "Hyperlink.worksheet", [Worksheet], worksheet @worksheet = worksheet @target = :external yield self if block_given? end |
Instance Attribute Details
#ref ⇒ String
Cell location of hyperlink on worksheet.
32 33 34 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 32 def ref @ref end |
Instance Method Details
#id ⇒ String
The id of the relationship for this object
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_id ⇒ Hash
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.
75 76 77 |
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb', line 75 def location_or_id @target == :external ? { :"r:id" => id } : { :location => Axlsx::coder.encode(location) } end |
#relationship ⇒ Relationship
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.
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
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 |