summaryrefslogtreecommitdiffhomepage
path: root/examples/row_outlines_options_example.md
blob: 27406aa2cb2bf922e3ca1b9022680417eb2a65c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Description

Outline summary rows can be positioned below (default) or above the details, corresponding to "Summary rows below detail" option in Excel.

Outline level can be set with helper methods (preferred), or on per-row basis.

## Code

```ruby
require 'axlsx'

p = Axlsx::Package.new
wb = p.workbook

s = wb.styles
summary = s.add_style b: true

wb.add_worksheet(name: 'Row outlines options') do |sheet|
  # This option specifies whether summary rows go above or below detail, worksheet-wide
  sheet.sheet_pr.outline_pr.summary_below = false

  # When specifying outline levels without helper methods, you must enable outline symbols manually.
  sheet.sheet_view.show_outline_symbols = true

  (1..4).map do |x|
    sub_group_hidden = x % 2 == 0

    x_row = sheet.add_row ["Group #{x}"], style: summary
    # Outline depth level can be set as property on the row
    x_row.outline_level = 0

    (1..4).map do |y|
      y_row = sheet.add_row ["  Item #{x}-#{y}"]
      y_row.outline_level = 1

      # Whether or not the outline level starts collapsed is governed by the `hidden` property on the row
      y_row.hidden = sub_group_hidden
    end
  end
end

p.serialize 'row_outlines_options_example.xlsx'
```

## Output

![Output](images/row_outlines_options_example_1.png "Output")