Class: Writexlsx::Worksheet::ExternalHyperlink
- Defined in:
- lib/write_xlsx/worksheet/hyperlink.rb
Constant Summary
Constants inherited from Hyperlink
Constants included from Utility
Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX
Instance Attribute Summary
Attributes inherited from Hyperlink
Instance Method Summary collapse
-
#initialize(url, str, tip) ⇒ ExternalHyperlink
constructor
A new instance of ExternalHyperlink.
Methods inherited from Hyperlink
#attributes, #display_on, #external_hyper_link, factory
Methods included from Utility
#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #palette_color, #pixels_to_points, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str
Constructor Details
#initialize(url, str, tip) ⇒ ExternalHyperlink
Returns a new instance of ExternalHyperlink.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/write_xlsx/worksheet/hyperlink.rb', line 119 def initialize(url, str, tip) # The displayed string defaults to the url string. str ||= url.dup # For external links change the directory separator from Unix to Dos. url = url.gsub(%r|/|, '\\') str.gsub!(%r|/|, '\\') # Strip the mailto header. str.sub!(/^mailto:/, '') # Escape URL unless it looks already escaped. url = escape_url(url) # External Workbook links need to be modified into the right format. # The URL will look something like 'c:\temp\file.xlsx#Sheet!A1'. # We need the part to the left of the # as the URL and the part to # the right as the "location" string (if it exists). url, url_str = url.split(/#/) # Add the file:/// URI to the url if non-local. if url =~ %r![:]! || # Windows style "C:/" link. url =~ %r!^\\\\! # Network share. url = "file:///#{url}" end # Convert a ./dir/file.xlsx link to dir/file.xlsx. url = url.sub(%r!^.\\!, '') # Excel limits escaped URL to 255 characters. if url.bytesize > 255 raise "URL '#{url}' > 255 characters, it exceeds Excel's limit for URLS." end @url = url @str = str @url_str = url_str @tip = tip end |