1

I have a Ruby code that iterates over some objects creating the necessary rows in an xls file using Axlsx gem.

Some of the object attributes are links (social handles and website), and I want these to be displayed as clickable links in the xls file. There can be multiple different links in the same cell, and I want each one to be a hyperlink.

So the question is, is there a way to tell the workbook to auto detect cells that contain texts that are links and display them as hyperlinks (like Word does when you type)?

Or if there is not, How can I make a certain cell be displayed as hyperlink?

This is the code I use to create the rows:

package = Axlsx::Package.new
package.use_shared_strings = true
package.use_autowidth = true
workbook = package.workbook

workbook.add_worksheet(name: sheet_name) do |sheet|
  add_headings_row(sheet)

  businesses.each do |business|
    [:id, name, :website, :social_handles, :phone].each do |method_name|
      columns << business.send(method_name)
    end

    sheet.add_row(columns, style: rows_style)
  end
end

What I'm asking is not how to make a single cell a hyperlink, that has been answered here, but how to automatically detect the text in a cell to be clickable (not the whole cell because there can be multiple links in the same cell), or at least how to manually make each line be clickable.

Leticia Esperon
  • 2,499
  • 1
  • 18
  • 40
  • 1
    Lines of text cannot be hyperlinks in excel, the cell can be a hyperlink but not the text itself. Otherwise I am not sure what you mean by "...how to automatically detect the text in a cell to be clickable..." If you are saying parse the text to determine if it is a URI (or contains a URI) then the `URI` class might help you with that but the question is a bit unclear as to your intentions – engineersmnky Jan 03 '20 at 13:56
  • Thank you, you answered the question by saying that "Lines of text cannot be hyperlinks in excel, the cell can be a hyperlink but not the text itself." Thank you – Leticia Esperon Jan 03 '20 at 21:20

0 Answers0