rubyxlsxrubyxl

How to access the column/row info of existing content of a xlsx file


I want to get the info of the last column and row of an existing xlsx file so that I can append new contents right below the existing content. How do I do so with RubyXL? If that's not possible, what alternative gem would you recommend?


Solution

  • As I wrote in my comment, I don't know if this is exactly what you are looking for:

    require 'rubyXL'
    
    workbook = RubyXL::Parser.parse("Workbook1.xlsx")
    worksheet = workbook[0]
    
    rows = worksheet.map {|row| row && row.cells.each { |cell| cell && cell.value != nil}}
    p last_row = rows.size
    p last_column = rows.compact.max_by{|row| row.size}.size