Class: HTOTConv::Generator::XlsxType1

Inherits:
XlsxBase show all
Defined in:
lib/htot_conv/generator/xlsx_type1.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XlsxBase

#output

Methods inherited from Base

#initialize, #output

Constructor Details

This class inherits a constructor from HTOTConv::Generator::Base

Class Method Details

.option_helpObject



10
11
12
13
14
15
16
17
18
# File 'lib/htot_conv/generator/xlsx_type1.rb', line 10

def self.option_help
  {
    :outline_rows => {
      :default => false,
      :pat => FalseClass,
      :desc => "group rows (default: no)",
    },
  }
end

Instance Method Details

#output_to_worksheet(ws) ⇒ Object



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/htot_conv/generator/xlsx_type1.rb', line 20

def output_to_worksheet(ws)
  max_value_length = @data.max_value_length

  ws.add_row([@data.key_header[0]].concat(
    HTOTConv::Util.pad_array(@data.value_header, max_value_length)),
  :style => Axlsx::STYLE_THIN_BORDER)

  @data.item.each do |item|
    ws.add_row([item.key].concat(
      HTOTConv::Util.pad_array(item.value, max_value_length)),
    :style => Axlsx::STYLE_THIN_BORDER)
  end

  if @option[:outline_rows]
    max_level = @data.max_level
    outline_begin = Array.new(max_level, nil)
    dummy_end_item = HTOTConv::Outline::Item.new(nil, 1, nil)
    @data.item.concat([dummy_end_item]).each_with_index do |item, item_index|
      (item.level..max_level).each do |level|
        if outline_begin[level - 1]
          if outline_begin[level - 1] < item_index - 1
            ws.outline_level_rows((outline_begin[level - 1] + 1) + 1, (item_index - 1) + 1, level, false)
          end
          outline_begin[level - 1] = nil
        end
      end
      outline_begin[item.level - 1] = item_index
    end

    # PR randym/axlsx#440 has been added to master branch
    # https://github.com/randym/axlsx/commit/c80c8b9d9be5542471d66afcc2ce4ddd80cac1f7
    # but latest release on rubygems does not contain this.
    # So apply monkey patch to ws.sheet_pr.
    if defined? ws.sheet_pr.outline_pr
      ws.sheet_pr.outline_pr.summary_below = false
    else
      class << ws.sheet_pr # monkey patch
        def to_xml_string(str="".dup)
          tmp_str = "".dup
          super(tmp_str)
          str << tmp_str.sub('<pageSetUpPr', '<outlinePr summaryBelow="0" /><pageSetUpPr')
        end
      end
    end
  end
end