ruby - rubyXL iterate through specific column from xslx -


i new ruby , rubyxl , have (maybe) simple question. have excel file parse rubyxl.

then want save values column b array. , don't know how done. maybe can me?

@workbook = rubyxl::parser.parse(path) . . . @excelcolumnb = array.new #only iterate column b (1)     @workbook.worksheets[0].each[1] { |column|   column.cells.each { |cell|     val = cell && cell.value     excelcolumnb.push(val)     puts val   } } return excelcolumnb 

i know example wrong. tried many things.

the each[1] main problem. can't index iterator way, it's syntactically incorrect. block variable contains row, not column.

try this:

@workbook.worksheets[0].each { |row|   val = row[1].value   @excelcolumnb << val   puts val } 

but recommend more succinct way create array:

@col_b = workbook.worksheets[0].collect {|row| row[1].value} 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -