4

I've been asked to create an Excel (.xlsx) report with collapsed rows and columns.

The application is in ruby/rails using axlsx gem for excel generation.

For the moment I cannot have the collaped symbol "+" facing the hidden row or column that allows to show/hide the rows/columns.

Anybody knows how can I create this collapsing effect? Even with another technology ?

Thanks,

Michael

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
Michael A.
  • 2,288
  • 1
  • 18
  • 21

1 Answers1

4

This can be done with axlsx.

require 'axlsx'
xlsx = Axlsx::Package.new
wb = xlsx.workbook
wb.add_worksheet(name: 'outline') do |sheet|
  sheet.add_row [nil, nil, nil, nil, nil, nil, nil, Time.now, 149455.15]
  sheet.add_row [nil, nil, nil, nil, nil, nil, nil, Time.now,14100.19]
  sheet.add_row [9500002267,  'foo', 'bar', 'penut', nil, 1212, 1212, Time.now,14100.19]
  sheet.rows[0..2].each do |row|
    row.outline_level = 1
  end
  sheet.column_info[0..2].each do |col|
    col.outline_level = 1
  end
  # This is required to show the [+] symbols
  sheet.sheet_view do |view|
    view.show_outline_symbols=true
  end
end
xlsx.serialize 'outline.xlsx'

You need to specify the outline_level on the row or column_info you are interested in and set show_ouline_symobols to true.

Best

randym

randym
  • 2,430
  • 1
  • 19
  • 18