Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/rubyXL/convenience_methods/cell.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module RubyXL
module CellConvenienceMethods
EXCEL_HYPERLINK_LIMIT_PER_WORKSHEET = 65_530 # Excel has a hard limit of 65,530 hyperlinks per Worksheet. HYPERLINK formulas are not included in this limit.

def change_contents(data, formula_expression = nil)
validate_worksheet

Expand Down Expand Up @@ -263,6 +265,15 @@ def add_hyperlink(url, tooltip = nil)
hyperlink = RubyXL::Hyperlink.new(:ref => self.r, :r_id => r_id)
hyperlink.tooltip = tooltip if tooltip
worksheet.hyperlinks ||= RubyXL::Hyperlinks.new

if worksheet.hyperlinks.size >= EXCEL_HYPERLINK_LIMIT_PER_WORKSHEET # Do not create hyperlinks once the Excel limit of 65,530 is reached. Return false.
unless @excel_hyperlink_limit_per_worksheet_warned
Rails.logger.warn("Excel hyperlink limit (65,530) reached in worksheet '#{worksheet.sheet_name}' at row #{row}, column #{column}. Further hyperlinks skipped.")
@excel_hyperlink_limit_per_worksheet_warned = true
end
return false
end

worksheet.hyperlinks << hyperlink
end

Expand Down
3 changes: 3 additions & 0 deletions lib/rubyXL/worksheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def add_cell(row_index = 0, column_index = 0, data = '', formula = nil, overwrit
end
c.raw_value = data
c.datatype = RubyXL::DataType::RAW_STRING
if data.match?( URI::DEFAULT_PARSER.make_regexp ) # If content is a URL then use the HYPERLINK formula to make it clickable.
c.formula = RubyXL::Formula.new(:expression => %(HYPERLINK("#{ data }")))
end
when RubyXL::RichText then
if data.to_s.length > TEXT_LENGTH_LIMIT_IN_CELL
raise ArgumentError, "The maximum length of cell contents (text) is #{TEXT_LENGTH_LIMIT_IN_CELL} characters"
Expand Down