我目前正在使用roo来阅读一组电子表格。当我对每一行进行迭代时(我跳过标题行等),我希望能够跳过某些行。有没有办法做到这一点?我想我可以在循环中使用一个索引,但我想知道是否有一个" roo"这样做的方法。
类似:
spreadsheet.each(c1: "Column1", c2: "Column2") do |therow|
next if therow.row(1)
end
谢谢!
答案 0 :(得分:0)
要跳过标题行,您可以从第2行开始到last_row,如下所示:
header = spreadsheet.row(1)
(2..spreadsheet.last_row).map do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
if your_condition
//do something otherwise ignore the row
end
end
希望有所帮助