Search code examples
ruby-on-railsrubyxlsxaxlsx

Axlsx_rails. Set height of multiple rows at once


I'm generating *.xlsx files using axlsx_rails based on xlsx gem.

I'm setting height for single row like this:

sheet.add_row [1,2,3,4,5,6], :style => predefined_style, :height => 14.3

How could I set height for a batch of rows, and if it possible, which declaration has higher priority?


Solution

  • The best I know of is to set the height on each row:

    sheet.rows.values_at(1,2,5,6).each {|row| row.height = 40}
    

    If necessary you can gain access to the sheets through the workbook:

    sheet = workbook.worksheets.first
    # or
    sheet = workbook.sheet_by_name("Sheet Name")
    

    Whichever statement comes later has priority (meaning it isn't like CSS where inline has higher priority.)