How to I add a hyperlink to a cell in axlsx?

徘徊边缘 提交于 2019-12-06 07:12:15

问题


With the spreadsheet gem, you can run Spreadsheet::Link.new('http://hyperlinkhere.com', 'Some words') to make a spreadsheet with a cell containing the string "Some words" with a hyperlink leading to "http://hyperlinkhere.com."

What's the axlsx equivalent?

EDIT: What if I want to write a row with more than one cell?

With spreadsheet, you can do this:

        newSheetRow[13] = Spreadsheet::Link.new('url.com','text')
        newSheetRow[14] = 'some text'

How do I do that with axlsx's .add_row method?


回答1:


You can add both links within workbook and URLs.

p = Axlsx::Package.new
book = p.workbook
book.add_worksheet(:name => 'hyperlinks') do |sheet|
  # external references
  sheet.add_row ['axlsx']
  sheet.add_hyperlink :location => 'https://github.com/randym/axlsx', :ref => sheet.rows.first.cells.first
  # internal references
  sheet.add_hyperlink :location => "'Next Sheet'!A1", :ref => 'A2', :target => :sheet
  sheet.add_row ['next sheet']
end


来源:https://stackoverflow.com/questions/29832835/how-to-i-add-a-hyperlink-to-a-cell-in-axlsx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!