使用RubyXL,我想知道我的迭代是什么行号。
workbook = RubyXL::Parser.parse("./file.xlsx")
worksheet = workbook[0]
worksheet.each do |row|
test0 = row[0].value
line = ????
puts "Line number #{line} - Value = #{test0}"
end发布于 2020-01-13 21:29:55
您可以使用#each_with_index并按如下方式编写:
workbook = RubyXL::Parser.parse("./file.xlsx")
workbook.first.each_with_index do |row, index|
puts "Line number #{index} - Value = #{row[0].value}"
end发布于 2020-01-13 20:58:36
可以在循环时使用each_with_index方法来获得迭代的当前行号。
worksheet.each_with_index do |row, index|
test0 = row[0].value
line = index
puts "Line number #{line} - Value = #{test0}"
endhttps://stackoverflow.com/questions/59722393
复制相似问题