Ruby Roo宝石:如何从包含超链接的单元格中提取超链接文本



我有MS Excel电子表格,其中有许多带有超链接的单元格。我不想要超链接。相反,我只想使用单元格中的可见文本。如何获取它们?

这是的样本代码

require 'roo-xls'
ifl = Roo::Spreadsheet.open(ifile)
sheet = ifl.sheet(0)
i = 0
while sheet.cell(i,0) != nil
key = sheet.cell(i,0) # these cells contain hyperlinks, not usual strings
puts key  # url is printed here instead of the visible text of the link
i = i + 1
end

有一种不同的方法来获取超链接:

sheet.hyperlink(row, column)

sheet.cell(i,0).to_s

最好把它转换成字符串。roo没有任何方法可以从细胞中移除超链接。

最新更新