Home > Mobile >  collecting excel rows with cells that are empty in ruby
collecting excel rows with cells that are empty in ruby

Time:07-08

Hey guys i have the following code in ruby:

@list = $workbook.worksheets[0].collect {|num,| num[12].value}

the problem is that there are some blank cells in row 12 and an error gets thrown whenever i try to execute. How can i read the blank cells as empty strings or maybe even skip the blank cells as they are not interesting?

I don't know much about ruby unfortunately (and blocks) but if someone can give me a quick solution i would be really thankful for the help.

CodePudding user response:

To save as empty strings

@list = $workbook.worksheets[0].map { |num| num[12]&.value.to_s }

To skip empty cells

@list = $workbook.worksheets[0].filter_map { |num| num[12]&.value }
  • Related