summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/row_breaks.rb
blob: 381dc0b6f8dd222674297d9a73f215a8eeeee9f2 (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
# frozen_string_literal: true

module Axlsx
  # A collection of break objects that define row breaks (page breaks) for printing and preview

  class RowBreaks < SimpleTypedList
    def initialize
      super Break
    end

    # Adds a row break
    # @param [Hash] options The options for the break to be created.
    # max and man values are fixed.
    # @see Break
    def add_break(options)
      # force feed the Excel default
      self << Break.new(options.merge(max: 16383, man: true))
      last
    end

    # <rowBreaks count="3" manualBreakCount="3">
    # <brk id="1" max="16383" man="1"/>
    # <brk id="7" max="16383" man="1"/>
    # <brk id="13" max="16383" man="1"/>
    # </rowBreaks>
    def to_xml_string(str = +'')
      return if empty?

      str << '<rowBreaks count="' << self.size.to_s << '" manualBreakCount="' << self.size.to_s << '">'
      each { |brk| brk.to_xml_string(str) }
      str << '</rowBreaks>'
    end
  end
end